help-octave
[Top][All Lists]

## list/cell

 From: Daniel Heiserer Subject: list/cell Date: Thu, 17 Jun 1999 08:20:01 +0200

```> But I use it everyday. I do new development (only possible) with it.
>
> >
> > Anyway may I make a suggestion before it becomes unbleedy,
> > and causes endless matlab compatibility discussions and makes us all
> > sick
> > ......?
> >
> > matlabs cell uses {} not ().
> > So *PLEASE* use {} to create a list.
> > a{1}=[1 2 3 ];
> > Add multidimensions to it. This *COULDN'T* be any problem.
>
> a patch please. I need it. Really!

Hi joe,
I am not used to octave development in detail.
I haven't submitted one patch on C/C++ base only m-files right now.
I hope to get deeper into it, because there are so many things I would
like to do with it, which require cells/lists, sparse-stuff and better
graphics.
Also my time-budget is really tight, but I will help whatever and
whenever I can.

Are you doing/implementing the list/cell-stuff?
I can provide you with "what matlab can and does".
I can maybe give you also some hints how to do things ....

1) Multidimensions are easy, as long as there is no operation defined
which uses explicitly the array structure (e.g. matrix multiplication).

Assume "a" is a list/cell of size 4x3 (mxn).
a{3,2} (in general i,j) would mean the 8-th (depending on c or fortran
indexing (i-1)*n+j or i+(j-1)*m) cell of the list/cell.
1 2 3, 1 2 3, 1 2 3, 1 2 3
^
1 2 3  4 5 6  7 8 9  10 11 12

For more dimensions it is similar.

2) How to create/acess cells in matlab:
>> help cell

CELL  Create cell array.
CELL(N) is an N-by-N cell array of empty matrices.

CELL(M,N) or CELL([M,N]) is an M-by-N cell array of empty
matrices.

CELL(M,N,P,...) or CELL([M N P ...]) is an M-by-N-by-P-by-...
cell array of empty matrices.

CELL(SIZE(A)) is a cell array the same size as A containing
all empty matrices.

>> ll=cell(2,3)

ll =

[]     []     []
[]     []     []

>> ll(1)

ans =

{[]}

>> ll{1}

ans =

[]

>> a=ll(1)

a =

{[]}

>> whos
Name      Size         Bytes  Class

a         1x1              8  cell array
ans       0x0              0  double array
ll        2x3             48  cell array

Grand total is 7 elements using 56 bytes

>> b=ll{1}

b =

[]

>> whos
Name      Size         Bytes  Class

a         1x1              8  cell array
ans       0x0              0  double array
b         0x0              0  double array
ll        2x3             48  cell array

Grand total is 7 elements using 56 bytes

>> ll{1}=[1 2 3 4 5]

ll =

[1x5 double]     []     []
[]     []     []

>> c.a=1;c.b=ll{1};
>> ll{1,2}=c

ll =

[1x5 double]    [1x1 struct]     []
[]              []     []

>> whos
Name      Size         Bytes  Class

a         1x1              8  cell array
ans       0x0              0  double array
b         0x0              0  double array
c         1x1            352  struct array
ll        2x3            664  cell array

Grand total is 28 elements using 1024 bytes

>> ll{2,2}=ll;
>> ll

ll =

[1x5 double]    [1x1 struct]     []
[]    {2x3 cell  }     []

>> whos
Name      Size         Bytes  Class

a         1x1              8  cell array
ans       0x0              0  double array
b         0x0              0  double array
c         1x1            352  struct array
ll        2x3           1440  cell array

Grand total is 47 elements using 1800 bytes

>> a={1 [] zeros(3)}

a =

[1]     []    [3x3 double]

>> whos
Name      Size         Bytes  Class

a         1x3            440  cell array

Grand total is 13 elements using 440 bytes

>> quit

--
Mit freundlichen Gruessen
Daniel Heiserer
-----
--------------------------------------------------------------
Dipl.-Phys. Daniel Heiserer, BMW AG, Knorrstrasse 147, 80788 Muenchen
Abteilung EK-20
Tel.: 089-382-21187, Fax.: 089-382-42820

---------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.  To ensure