help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Sergei Steshenko
Subject: '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 03:39:11 -0800 (PST)

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
}
octave:3> foo{:}
ans =  5
octave:4> bar = [5]
bar =  5
octave:5>  

".

OTOH, in 
http://www.gnu.org/software/octave/doc/interpreter/The-_003ccode_003efor_003c_002fcode_003e-Statement.html#The-_003ccode_003efor_003c_002fcode_003e-Statement
 I read:

"
In this case the variable i takes on the value of the columns of
the matrix or cell matrix.  So the first loop iterates twice, producing
two column vectors [1;2], followed by [3;4], and likewise
for the loop over the cell array. 

".

I have doubts regarding "i takes on the value of the columns" vs the observed 
behavior. I.e., for example,

"
foo =
{
  [1,1] =  5
}
"

doesn't look to me like a column (vector), though both
"
foo{:}
ans =  5
"

and

"
bar = [5]
bar =  5
"

do look to me like one element column or row vector - since there is just one 
element, it doesn't matter whether the vector is column or row.

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 ?

To make my doubt more clear, the output (the 'foo' variable value) looks like 
yet another cell array to me, not like a (column) vector.


Maybe is a Matlab compatibility thing ?

Thanks,
  Sergei.


reply via email to

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