MATLAB: Repeat parts of a matrix

matrix manipulation

Hi!
I have a matrix A = (1 2; 3 4 ; 5 6; 7 8; 9 10; 11 12). I am trying to create a matrix B in which the consecutive 2×2 submatrices of A are repeated lets say 2 times. Therefore B = [1 2; 3 4; 1 2; 3 4; 5 6; 7 8; 5 6; 7 8; 9 10; 11 12; 9 10; 11 12]. How can I do that?
Thank a lot!
Filippos

Best Answer

This should work
B = [1 2; 3 4; 1 2; 3 4; 5 6; 7 8; 5 6; 7 8; 9 10; 11 12; 9 10; 11 12];
A = [1 2; 3 4 ; 5 6; 7 8; 9 10; 11 12];
C=reshape(A',4,3);
C=[C;C];
C=reshape(C,2,12);
C=C';