cell

Create cell array

Syntax

C = cell(dim)
C = cell(dim1,...,dimN)
D = cell(obj)

Description

C = cell(dim) creates a cell array of empty matrices. If dim is a scalar, C is dim-by-dim. If dim is a vector, C is dim(1)-by-...-dim(N), where N is the number of elements of dim.

C = cell(dim1,...,dimN) creates cell array C, where C is dim1-by-...-dimN.

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

Input Arguments

dim

Scalar integer or vector of integers that specifies the dimensions of cell array C.

dim1,...,dimN

Scalar integers that specify the dimensions of C.

obj

One of the following:

  • Java array or object

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

Output Arguments

C

Cell array. Each cell contains an empty, 0-by-0 array of type double.

D

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

Examples

Create an empty 3-by-4-by-2 cell array.

mycell = cell(3,4,2);

Create a cell array that is the same size as mycell, created in the previous example.

similar = cell(size(mycell));

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

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

cellArray = cell(strArray)

This code returns

cellArray = 
    'one'
    'two'
    'three'

Create a cell array of folders in the c:\work folder, using the .NET Framework System.IO.Directory class :

myList = cell(System.IO.Directory.GetDirectories('c:\work'));
celldisp(myList)

More About

expand all

Tips

Creating an empty array with the cell function, such as

C = cell(3,4,2);

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

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

See Also

| | | | |

Was this topic helpful?