Preallocate Memory for a Cell Array

This example shows how to initialize and allocate memory for a cell array.

Cell arrays do not require completely contiguous memory. However, each cell requires contiguous memory, as does the cell array header that MATLAB® creates to describe the array. For very large arrays, incrementally increasing the number of cells or the number of elements in a cell results in Out of Memory errors.

Initialize a cell array by calling the cell function, or by assigning to the last element. For example, these statements are equivalent:

C = cell(25,50);
C{25,50} = [];

MATLAB creates the header for a 25-by-50 cell array. However, MATLAB does not allocate any memory for the contents of each cell.

For more information, see:

Was this topic helpful?