MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Add Cells to Cell Array


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

Create a 1-by-3 cell array.

C = {1, 2, 3}

C = 1x3 cell array
{[1]} {[2]} {[3]}

Assign data to a cell outside the current dimensions. MATLAB® expands the cell array to
a rectangle that includes the specified subscripts. Any intervening cells contain empty
arrays.

C{4,4} = 44

C = 4x4 cell array
{[ 1]} {[ 2]} {[ 3]} {0x0 double}
{0x0 double} {0x0 double} {0x0 double} {0x0 double}
{0x0 double} {0x0 double} {0x0 double} {0x0 double}
{0x0 double} {0x0 double} {0x0 double} {[ 44]}

Add cells without specifying a value by assigning an empty array as the contents of a cell.
C is now a 5-by-5 cell array.

C{5,5} = []

C = 5x5 cell array
Columns 1 through 4

{[ 1]} {[ 2]} {[ 3]} {0x0 double}
{0x0 double} {0x0 double} {0x0 double} {0x0 double}
{0x0 double} {0x0 double} {0x0 double} {0x0 double}
{0x0 double} {0x0 double} {0x0 double} {[ 44]}
{0x0 double} {0x0 double} {0x0 double} {0x0 double}

Column 5

{0x0 double}
{0x0 double}
{0x0 double}

12 Cell Arrays

Free download pdf