[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 'for' loop on elements of cell array (octave-3.4.2) - is it the way
From: |
Ben Abbott |
Subject: |
Re: 'for' loop on elements of cell array (octave-3.4.2) - is it the way it is supposed to be ? |
Date: |
Thu, 02 Feb 2012 08:47:53 -0500 |
On Feb 2, 2012, at 6:39 AM, Sergei Steshenko wrote:
> Hello,
>
> I have tried the following piece of code:
>
> "
> octave:1> foolist = {1, 2, 5}
> foolist =
> {
> [1,1] = 1
> [1,2] = 2
> [1,3] = 5
> }
> octave:2> for foo = foolist foo endfor
> foo =
> {
> [1,1] = 1
> }
> foo =
> {
> [1,1] = 2
> }
> foo =
> {
> [1,1] = 5
> }
<snip>
> In other words, the output from the 'for' loop doesn't look like I expect,
> and if my expectations (I expected '1, 2, 5' sequence) are wrong, which part
> of GNU Octave documentations explains how the output should look ?
I'm confused. The output is 1, 2, 5.
The for loop below will run 3 times (once for each column)
for a = [1 2 3; 4 5 6; 7 8 9]
disp (a)
disp ('---')
end
1
4
7
---
2
5
8
---
3
6
9
---
This one will only perform one loop
for a = [1 2 3; 4 5 6; 7 8 9](:)
disp (a)
disp ('---')
end
1
4
7
2
5
8
3
6
9
---
And this one will perform 9 loops
for a = [1 2 3; 4 5 6; 7 8 9](:)'
disp (a)
disp ('---')
end
1
---
4
---
7
---
2
---
5
---
8
---
3
---
6
---
9
---
Does that clarify the behavior ?
Ben
- 'for' loop on elements of cell array (octave-3.4.2) - is it the way it is supposed to be ?, Sergei Steshenko, 2012/02/02
- Re: 'for' loop on elements of cell array (octave-3.4.2) - is it the way it is supposed to be ?,
Ben Abbott <=
- Re: 'for' loop on elements of cell array (octave-3.4.2) - is it the way it is supposed to be ?, Sergei Steshenko, 2012/02/02
- Re: 'for' loop on elements of cell array (octave-3.4.2) - is it the way it is supposed to be ?, James Sherman Jr., 2012/02/02
- Re: 'for' loop on elements of cell array (octave-3.4.2) - is it the way it is supposed to be ?, Sergei Steshenko, 2012/02/02
- Re: 'for' loop on elements of cell array (octave-3.4.2) - is it the way it is supposed to be ?, John W. Eaton, 2012/02/02
- Re: 'for' loop on elements of cell array (octave-3.4.2) - is it the way it is supposed to be ?, Sergei Steshenko, 2012/02/02
- Re: 'for' loop on elements of cell array (octave-3.4.2) - is it the way it is supposed to be ?, John W. Eaton, 2012/02/02
- Re: 'for' loop on elements of cell array (octave-3.4.2) - is it the way it is supposed to be ?, Sergei Steshenko, 2012/02/02
- Re: 'for' loop on elements of cell array (octave-3.4.2) - is it the way it is supposed to be ?, John W. Eaton, 2012/02/02