[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: For loops and column vectors
From: |
Ben Abbott |
Subject: |
Re: For loops and column vectors |
Date: |
Sun, 17 Jul 2011 13:31:54 -0400 |
On Jul 17, 2011, at 12:58 PM, Rik wrote:
> 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
You are correct, this behavior is consistent with Matlab's.
Ben