MATLAB: For loop options in Matlab

for loop indexing

I just learned about Matlab's ability to use matrices as arguments to a for loop;
This displays the columns of the matrix A
A = magic(5)
for n = A
disp(n)
end
I was wondering if it is possible to obtain a sequential index into a loop like this. ie. if I want to print the column number along with the column itself, can I continue with the form above or would I need to revert to a more typical form like
A = magic(5)
for jj = 1:length(A)
disp(['Column #',num2str(jj)])
disp(A(:,jj))
end

Best Answer

You would need the more traditional form. There is no way to query which iteration number you are on.