Documentation

cell

Create cell array

Syntax

Description

example

C = cell(n) returns an n-by-n cell array of empty matrices.

example

C = cell(sz1,...,szN) returns a sz1-by-...-by-szN cell array of empty matrices where sz1,...,szN indicate the size of each dimension. For example, cell(2,3) returns a 2-by-3 cell array.

example

C = cell(sz) returns a cell array of empty matrices where size vector sz defines size(C). For example, cell([2 3]) returns a 2-by-3 cell array.

example

D = cell(obj) converts a Java® array or .NET System.String or System.Object array into a MATLAB® cell array.

Examples

collapse all

Square Cell Array

Create a 3-by-3 cell array of empty matrices.

C = cell(3)
C = 

    []    []    []
    []    []    []
    []    []    []

3-D Cell Array

Create a 3-by-4-by-2 cell array of empty matrices.

C = cell(3,4,2);
size(C)
ans =

     3     4     2

Clone Size from Existing Array

Create a cell array of empty matrices that is the same size as an existing array.

A = [7 9; 2 1; 8 3];
sz = size(A);
C = cell(sz)
C = 

    []    []
    []    []
    []    []

It is a common pattern to combine the previous two lines of code into a single line.

C = cell(size(A));

Cell Array from Java Array

Convert an array of java.lang.String objects into a cell array.

X = java_array('java.lang.String', 3);
X(1) = java.lang.String('one');
X(2) = java.lang.String('two');
X(3) = java.lang.String('three');
D = cell(X)
D = 

    'one'
    'two'
    'three'

Cell Array from .NET Array

Convert a .NET array of System.Double objects into a cell array.

N = NET.createArray('System.Double[]',2);
N(1) = [13 7 30];
N(2) = 42;
D = cell(N)
D = 

    [1x3 double]    [42]

Related Examples

Input Arguments

collapse all

n — Size of square cell arrayinteger value

Size of a square cell array, specified as an integer value.

  • If n is 0, then C is an empty cell array.

  • If n is negative, then it is treated as 0.

Data Types: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

sz1,...,szN — Size of each dimension (as separate arguments)integer values

Size of each dimension, specified as separate arguments of integer values.

  • If the size of any dimension is 0, then C is an empty cell array.

  • If the size of any dimension is negative, then it is treated as 0.

  • Beyond the second dimension, cell ignores trailing dimensions with a size of 1. For example, cell([3,1,1,1]) produces a 3-by-1 cell array of empty matrices.

Data Types: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

sz — Size of each dimension (as a row vector)integer values

Size of each dimension, specified as a row vector of integer values. Each element of this vector indicates the size of the corresponding dimension.

  • If the size of any dimension is 0, then C is an empty cell array.

  • If the size of any dimension is negative, then it is treated as 0.

  • Beyond the second dimension, cell ignores trailing dimensions with a size of 1. For example, cell([3,1,1,1]) produces a 3-by-1 cell array of empty matrices.

Example: sz = [2, 3, 4] creates a 2-by-3-by-4 cell array of empty matrices.

Data Types: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

obj — Input arrayJava array or object | .NET array of type System.String or System.Object | Python® sequence type

Input array, specified as:

  • Java array or object

  • .NET array of type System.String or System.Object

  • Python sequence type

Output Arguments

collapse all

C — Output arraycell array

Output array, returned as a cell array. Each cell contains an empty, 0-by-0 array of type double.

D — Converted arraycell array

Converted array, returned as a cell array.

Each cell contains a MATLAB type closest to the Java or .NET type. For more information, see:

More About

collapse all

Tips

  • Creating an empty array with the cell function, such as

    C = cell(3,4,2);

    is equivalent to assigning an empty array to the last index of a new cell array:

    C{3,4,2} = [];

See Also

|

Introduced before R2006a

Was this topic helpful?