Is the below difference intended functionality or a bug?
x = [1, 2, 3, 4];for y = x disp( 'Printing' ); disp( y );end
Result:
Printing 1Printing 2Printing 3Printing 4
Whereas if I transpose x, the loop only runs once with y = [1; 2; 3; 4].
x = [1, 2, 3, 4]';for y = x disp( 'Printing' ); disp( y );end
Result:
Printing 1 2 3 4
Perhaps I'm being thick, but I can't find this behavior documented anywhere and I would have expected it to loop through the elements in the matrix/array as if it were one dimensional (linear indexing).
Best Answer