MATLAB: Insert rows and columns in a matrix

insert rows and columns in a matrixMATLABmatrix manipulation

Hello,
I have a 3×3 matrix and I want to make it 4×4 matrix by inserting a row and column of zero elements. How can I do that?
Thanks,
Rakesh

Best Answer

One approach:
M = rand(3);
Mz = zeros(size(M,1)+1, size(M,2)+1);
Mz(1:size(M,1), 1:size(M,2)) = M;
producing (here):
Mz =
0.95717 0.14189 0.79221 0
0.48538 0.42176 0.95949 0
0.80028 0.91574 0.65574 0
0 0 0 0
Experiment to get the result you want.