MATLAB: Can I store row numbers of a matrix in a column without using any loop

looprow numbers

How will I store the first column of a matrix as its corresponding row number without using a loop. That is, the first column for a 3×3 matrix as [1 . .;2 . .;3 . .].

Best Answer

a = magic(3);
a(:, 1) = [1:3]; % This will store the row index in the first column of 'a'