MATLAB: How to add a column of zeros to a magic 5×5 matrix A to create a 5×6 matrix C

add column zeros

How can I add a column of zeros to a magic 5×5 matrix A to create a 5×6 matrix C? The element value in the 6th column should all be zero.

Best Answer

Try this:
A = magic(5)
C = A; % Initialize a brand new matrix called C that is the same as A.
C(5,6) = 0 % Add column 6 that is all zeros.
Related Question