MATLAB: Putting 1 around the matrix

putting 1 around the matrix

Hi I have a 3X3 matrix and want to put 1 around the matrix as it will become 4X4 matrix…..

Best Answer

Let A - your matrix [3 x 3]:
A = magic(3);
out = ones(2 + size(A));
out(2:end-1,2:end-1) = A;
Related Question