MATLAB: How to insert rows and colums of zeroes in this matrix ??? a=[1 2 3;4 5 6]

MATLAB

how to insert rows and colums of zeroes in this matrix ??? a=[1 2 3;4 5 6]

Best Answer

Here is one quick way to interlace columns and rows of zeros:
>> a=[1 2 3;4 5 6];
>> b = zeros(2*size(a));
>> b(1:2:end,1:2:end) = a
b =
1 0 2 0 3 0
0 0 0 0 0 0
4 0 5 0 6 0
0 0 0 0 0 0
Related Question