MATLAB: Is there any way to put a small matrix diagonally into a larger one

concatanationdiagonalmatrix

ex: [1 2;3 4]
Big matrix :[1 2 0 0 0 0; 3 4 0 0 0 0; 0 0 1 2 0 0 0 0 3 4 0 0]

Best Answer

A = [1 2; 3 4];
B = zeros(4,6);
B(1:2,1:2) = A;
B(3:4,3:4) = A;