You can create the matrix in one line of code using the following MATLAB expression:
main.m52 chars2 lines
Explanation:
eye(3)
creates a 3x3 identity matrix.repmat([2;2], 1, 2)
creates a 2-element column vector [2;2]
and replicates it horizontally twice to create a 2x2 matrix [2, 2; 2, 2]
.repmat(3, 2, 5)
creates a 2x5 matrix where all elements are equal to 3.[]
concatenates the matrices vertically.The resulting matrix M
will be a 5x5 matrix with eye(3) as the first three columns, columns 4 and 5 filled with 2's, and the last two rows filled with 3's.
gistlibby LogSnag