R matlab package: why is repmat incompatible?

I have a question about matlab package for R. That's what I get

library(matlab) a = matrix(1:4,2,2) repmat(a,3,1) [,1] [,2] [1,] 1 2 [2,] 3 4 [3,] 1 2 [4,] 3 4 [5,] 1 2 [6,] 3 4 

this is what i expect. repeat three times in the first measurement. but

 b = matrix(1:6,2,3) b [,1] [,2] [,3] [1,] 1 3 5 [2,] 2 4 6 repmat(b,3,1) [,1] [,2] [1,] 1 2 [2,] 3 4 [3,] 5 6 [4,] 1 2 [5,] 3 4 [6,] 5 6 [7,] 1 2 [8,] 3 4 [9,] 5 6 

it is consistent. I want a 6 by 3 matrix to be obtained with

 rbind(b,rbind(b,b)) [,1] [,2] [,3] [1,] 1 3 5 [2,] 2 4 6 [3,] 1 3 5 [4,] 2 4 6 [5,] 1 3 5 [6,] 2 4 6 
+4
source share
1 answer

It seems that this is simply transposing the matrix before performing stacking. You can just transfer your matrix before sending it to repmat

 > repmat(t(b), 3, 1) [,1] [,2] [,3] [1,] 1 3 5 [2,] 2 4 6 [3,] 1 3 5 [4,] 2 4 6 [5,] 1 3 5 [6,] 2 4 6 
+3
source

Source: https://habr.com/ru/post/1478990/


All Articles