You can create a 5x5 matrix with 1s in the first 3x3 and zeros elsewhere in one line of code using the following MATLAB code:
main.m39 chars2 lines
Explanation:
ones(3)
creates a 3x3 matrix of ones.zeros(3,2)
creates a 3x2 matrix of zeros to fill the remaining columns in the first 3 rows.zeros(2,5)
creates a 2x5 matrix of zeros for the last 2 rows.;
, we get a 5x5 matrix with 1s in the first 3x3 and zeros elsewhere.gistlibby LogSnag