Skip to main content

8.1) Introducing Cell Arrays


Cell arrays are arrays that can hold data of different types (including arrays). Common applications include storing lists of text strings or other heterogeneous data involving numbers.

Cell arrays are indexed much like matrices but we use curly brackets { } both to create them and to access their elements:

[matlab]
>> a = {'one', 'two', 'three' ; 1, 2, 3}
>> a=
'one' 'two' 'three'
[ 1] [ 2] [ 3]
>> size(a)
ans= 2x3
[/matlab]

We can create an empty cell array with the command "cell":

[matlab]
>> b=cell(2,3);
[/matlab]

There are two ways to access elements of a cell array:

  • Use round brackets to get one or more elements as a smaller cell array.
  • Use curly brackets to get the contents of single cells.