[MATLAB logo] Exploiting MATLAB's Data Structures

Cell Arrays - The Universal Container

Cell arrays are arrays where the elements are other arrays. This allows you to collect arrays of different types and sizes together. A common use of the cell array is to store strings (which may have different lengths) in the elements of a cell array.

Syntax:

c = {'hello', 17, magic(3)};
c{2} = 1:10;
c(2) = {17};

Examples:

strings
matrices of size N where N varies

Problem #1 - Rank of Magic Squares

Problem #2 - Cell Array of Strings

More info ...

Specialized cell functions

cell Create cell array
deal Deal input to outputs
num2cell Convert numeric array to cell

To convert cells to numbers when all the numbers are the same size, the easiest is to use comma separated list expansion with [ ] or cat.

Copyright © 1997 The MathWorks, Inc.
clay@mathworks.com
$Revision$ $Date$