Mar 27, 2012

Matlab Cell Array

Cell arrays is a tabular data structure in Matlab, useful for storing heterogeneous objects whereas arrays can hold only homogeneous objects. Elements in cell array can have different dimensions as well. Elements of cell array, called cells, can contain
  • numeric arrays
  • strings
  • structures
  • cell arrays
Following example code creates and populates a cell array :

A = {['1st element'] [2 3] [8 9 7; 1 2 3] ['a' 'b']};


Index is written within curly braces e.g. A{1} to access the elements of a cell array. To recursively display the contents of a cell array, celldisp function can be used. For example, celldisp(A) produces the following result


A{1} =

1st element


A{2} =

2 3



A{3} =

8 9 7
1 2 3



A{4} =

ab



The contents of a cell array can be visualized with cellplot function, cellplot(A) would produce the following visualization.



This entry on mathworks blog can be consulted for farther information.

No comments:

Post a Comment