23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2 Data Types<br />

C5 =<br />

'Jan' 'Feb' 'Mar' 'Apr' 'May' 'Jun'<br />

'10' '17' '31' '2' '10' '23'<br />

[2004] [2001] [2006] [2005] [1994] [2002]<br />

Preallocating Cell Arrays with the cell Function<br />

The cell function enables you to preallocate empty cell arrays of the specified<br />

size. For example, this statement creates an empty 20-by-30 cell array:<br />

B = cell(20, 30);<br />

Use assignment statements to fill the cells of B.<br />

It is more efficient to preallocate a cell array of a required size using the cell<br />

function and then assign data into it, than to grow a cell array as you go along<br />

using individual data assignments. The cell function, therefore, offers the<br />

most memory-efficient way of preallocating a cell array.<br />

Memory Requirements for Cell Arrays<br />

You do not necessarily need a contiguous block of memory to store a cell array.<br />

The memory for each cell needs to be contiguous, but not the entire array<br />

of cells.<br />

Referencing Cells of a Cell Array<br />

Because a cell array can contain different types of data stored in various<br />

array sizes, cell array indexing is a little more complex than indexing into a<br />

numeric or character array.<br />

This section covers the following topics on constructing a cell array:<br />

• “Manipulating Cells and the Contents of Cells” on page 2-101<br />

• “Working With Arrays Within Cells” on page 2-104<br />

• “Working With Structures Within Cells” on page 2-104<br />

• “Working With Cell Arrays Within Cells” on page 2-105<br />

• “Plotting the Cell Array” on page 2-106<br />

2-100

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!