[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
For loops and column vectors
From: |
Rik |
Subject: |
For loops and column vectors |
Date: |
Sun, 17 Jul 2011 09:58:13 -0700 |
6/17/11
All,
I came across what I consider to be odd behavior, but perhaps we are trying
to emulate Matlab or perhaps someone knows a better reason for this. In
short, the for loop construct works correctly when the range expression is
a row vector but not when it is a column vector.
Sample Code:
for i = [1:3]
disp (i);
disp ("--");
endfor
Output:
1
--
2
--
3
--
for i = [1:3]'
disp (i);
disp ("--");
endfor
Output:
1
2
3
--
In the second case the loop variable gets assigned the entire value of the
column vector and the loop iterates just once.
Any ideas?
Rik
- For loops and column vectors,
Rik <=