help-octave
[Top][All Lists]

## Re: 'for' loop on elements of cell array (octave-3.4.2) - is it the way

 From: Sergei Steshenko Subject: Re: 'for' loop on elements of cell array (octave-3.4.2) - is it the way it is supposed to be ? Date: Thu, 2 Feb 2012 07:25:40 -0800 (PST)

>________________________________
> From: James Sherman Jr. <address@hidden>
>Sent: Thursday, February 2, 2012 5:09 PM
>Subject: Re: 'for' loop on elements of cell array (octave-3.4.2) - is it the
>way it is supposed to be ?
>
>
>[snip]
>
>
>The behavior is consistent, as far as I can tell.  Look at the columns of your
>foolist:
>
>
>octave:9> foolist = {1,2,5}
>foolist =
>{
>  [1,1] =  1
>  [1,2] =  2
>  [1,3] =  5
>}
>octave:10> foolist(:,1)
>ans =
>{
>  [1,1] =  1
>}
>octave:11> foolist(:,2)
>ans =
>{
>  [1,1] =  2
>}
>octave:12> foolist(:,3)
>ans =
>{
>  [1,1] =  5
>}
>
>
>Each loop of your for statement output the corresponding column of foolist.
>
>
>Hope this helps.
>

I am not sure the behavior is consistent. That is, I am not sure an element of
cell array is _always_ cell array.

Here is my point:

"
octave:1> a_vector = [1 2 3]
a_vector =

1   2   3

octave:2> for foo = a_vector foo endfor
foo =  1
foo =  2
foo =  3

octave:3>

"
.

I have created a vector called 'a_vector', and to denote that it's a vector
I've used '[', ']' delimiters. Elements of the vector are _numeric_ and as such
they are displayed in the loop body as numeric _without_ delimiters - makes
sense to me.

With my cell array, though its elements are _numeric_ too, delimiters _are_
used to display 'foo' in the loop body. And it doesn't make sense to me.

Regards,
Sergei.