help-octave
[Top][All Lists]
Advanced

[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: 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 08:46:21 -0800 (PST)




----- Original Message -----
> From: John W. Eaton <address@hidden>
> To: Sergei Steshenko <address@hidden>
> Cc: James Sherman Jr. <address@hidden>; "address@hidden" <address@hidden>
> Sent: Thursday, February 2, 2012 6:27 PM
> Subject: Re: 'for' loop on elements of cell array (octave-3.4.2) - is it the 
> way it is supposed to be ?
> 
> On  2-Feb-2012, Sergei Steshenko wrote:
> 
> | I am not sure the behavior is consistent.
> 
> It is consistent.
> 
> Consider this case instead:
> 
>   cell_array = {[1,2;3,4], "foobar"; [5,6], {7, "foo", 
> [8,9,10]}};
> 
>   for elt = cell_array
>     elt
>   endfor
> 
> Do you see now why the columns must be extracted as cells, not the
> individual cell elements?
> 
> jwe
> 

Well, maybe. The code produces:

"
octave:1> cell_array = {[1,2;3,4], "foobar"; [5,6], {7, "foo", [8,9,10]}};
octave:2>
octave:2>   for elt = cell_array
>     elt
>   endfor
elt =
{
  [1,1] =

     1   2
     3   4

  [2,1] =

     5   6

}
elt =
{
  [1,1] = foobar
  [2,1] =
  {
    [1,1] =  7
    [1,2] = foo
    [1,3] =

        8    9   10

  }
}
octave:3>     
"

and it can make sense to me if I consider cell array to be a 2D matrix with 
possibly  "awkward" (arbitrary type) elements.

Should cell arrays be considered as 2D matrices ? If yes, which part of Octave 
documentation describes them as such ?

Thanks,
  Sergei.

".



reply via email to

[Prev in Thread] Current Thread [Next in Thread]