Add Cells to a Cell Array

This example shows how to add cells to a cell array.

Create a 1-by-3 cell array:

C = {1, 2, 3};

Assign data to a cell outside the current dimensions:

C{4,4} = 44

MATLAB® expands the cell array to a rectangle that includes the specified subscripts. Any intervening cells contain empty arrays:

C = 
    [1]    [2]    [3]      []
     []     []     []      []
     []     []     []      []
     []     []     []    [44]

Add cells without specifying a value by assigning an empty array as the contents of a cell:

C{5,5} = []

C is now a 5-by-5 cell array:

C = 
    [1]    [2]    [3]      []    []
     []     []     []      []    []
     []     []     []      []    []
     []     []     []    [44]    []
     []     []     []      []    []

For related examples, see:

Was this topic helpful?