next up previous contents
Next: Objects Up: Advanced data types in Previous: Structures

Cell arrays

A cell array is an array whose entries can be data of any type. The index operator {} is used in place of () to indicate that an array is a cell array instead of an ordinary array:

>> x = [2;1];
>> fx = f(x);
>> whos
  Name      Size         Bytes  Class

  fx        1x1            428  struct array
  x         2x1             16  double array

Grand total is 12 elements using 444 bytes

>> A{1}=x 
A = 
    [2x1 double]
>> A{2}=fx
A = 
    [2x1 double]    [1x1 struct]
>> whos
  Name      Size         Bytes  Class

  A         1x2            628  cell array
  fx        1x1            428  struct array
  x         2x1             16  double array

Grand total is 26 elements using 1072 bytes
Another way to create the same cell array is to place the entries inside of curly braces:
>> B = {x,fx}
B = 
    [2x1 double]    [1x1 struct]

For more information about cell arrays, see help cell.



Mark S. Gockenbach
Wed Sep 8 10:44:13 EDT 1999