R matlab package: why is repmat inconsistent?
matlab, package, r
Solution
It just appears to be transposing the matrix before doing the stacking. You could just transpose your matrix before sending it into `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
Problem
I have got a question regarding the matlab package for R. Here'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. replicate a three times along the first dimension. 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 ``` this is not consistent. I want a 6 by 3 matrix as the one obtained by ``` 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 ```