[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
why two indexes in 1d cell array ? (octave-3.4.2) ... how about more dim
From: |
Sergei Steshenko |
Subject: |
why two indexes in 1d cell array ? (octave-3.4.2) ... how about more dimensions ? |
Date: |
Wed, 10 Aug 2011 12:18:26 -0700 (PDT) |
Hello,
reading
http://www.gnu.org/software/octave/doc/interpreter/Cell-Arrays.html#Cell-Arrays
I see this:
"
A cell array is a container class able to do just that. In general cell arrays
work just like N-dimensional arrays with the exception of the use of ‘{’ and
‘}’ as allocation and indexing operators.
"
- mu understanding of "N-dimensional arrays" is that number of dimensions is
set as needed when user creates a cell array.
Reading on
http://www.gnu.org/software/octave/doc/interpreter/Basic-Usage-of-Cell-Arrays.html#Basic-Usage-of-Cell-Arrays
I see:
"
c = {"a string", rand(2, 2)};
",
I decided to further try this example:
"
octave:1> c = {"a string", rand(2, 2)}
c =
{
[1,1] = a string
[1,2] =
0.245929 0.096505
0.018941 0.231544
}
octave:2> size(c)
ans =
1 2
octave:3> c{1:2}
ans = a string
ans =
0.245929 0.096505
0.018941 0.231544
octave:4> celldisp(c)
c{1} =
a string
c{2} =
0.245929 0.096505
0.018941 0.231544
octave:5>
".
Questions/statements
1) in
"
c =
{
[1,1] = a string
[1,2] =
"
I see _two_ indexes, i.e. "[1,1]...", "[1,2]", though to me it looks like
created a _1d_ (just _one_ dimension) cell array;
2) in
"
octave:4> celldisp(c)
c{1} =
a string
c{2} =
0.245929 0.096505
0.018941 0.231544
octave:5>
"
I see just _one_ index ("c{1}...", "c{2}...".
So, why the discrepancy, i.e. in one case two indexes, and in the other
one ?
Why no indexes at all in
"
octave:3> c{1:2}
ans = a string
ans =
0.245929 0.096505
0.018941 0.231544
" ?
...
Another example:
"
octave:5> b = {1, 2, 3}
b =
{
[1,1] = 1
[1,2] = 2
[1,3] = 3
}
octave:6>
"
- there is _nothing_ 2d inside "b" - why still _two_ indexes ?
...
Can anybody please explain this:
"
octave:10> g{1,1,1,1} = 6
g =
{
[1,1] = 6
}
octave:11> celldisp(g, "g")
g{1} =
6
octave:12>
"
?
I.e. _definitely_ a 4-d array shows just two indexes in
"
octave:10> g{1,1,1,1} = 6
g =
{
[1,1] = 6
}
"
and at all just _one_ index in
"
octave:11> celldisp(g, "g")
g{1} =
6
".
...
I continue with that "g" cell array:
"
octave:12> g{1,1,1,2} = 7
g = {1x1x1x2 Cell Array}
octave:13> celldisp(g, "g")
g{1} =
6
g{2} =
7
octave:14>
".
...
An equivalent example with a matrix:
"
octave:14> gm(1,1,1,1) = 5
gm = 5
octave:15> gm(1,1,1,2) = 6
gm =
ans(:,:,1,1) = 5
ans(:,:,1,2) = 6
octave:16> gm
gm =
ans(:,:,1,1) = 5
ans(:,:,1,2) = 6
octave:17>
"
- makes more sense to me (i.e. I see all four dimensions), but not quite -
the ':' seems to be strange.
...
Oh-oh, with matrices there seem to be problems too, I'll write a
separate Email.
Is this all expected and documented behavior ?
Thanks,
Sergei.