MATLAB: Combining K matrices in one matrix

arrayMATLABmatrix

Hi, I have K matrices of size [n,m]. For example:
K = 3;
n = 4;
m = 3
a = [1 2 3; 4 5 6; 7 8 9; 4 7 2];
b = [1 5 6; 3 1 2; 7 2 5; 6 8 3];
c = [4 1 7; 5 8 6; 3 5 9; 5 3 8];
X = [a11 b11 c11; a21 b21 c21; a31 b31 c31; a41 b41 c41;
a12 b12 c12; a22 b22 c22; a32 b32 c32; a42 b42 c42;
a13 b13 c13; a23 b23 c23; a33 b33 c33; a43 b43 c43];
% aij, bij and cij are the indexes of an element in matrix a, b and c
Is it possible to combine matrices a, b and c to create X, without using for statement?

Best Answer

X = reshape(cat(3,a,b,c),[],3)