Create cell array


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


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


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


Scalar integers that specify the dimensions of C.


One of the following:

  • Java array or object

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

Output Arguments


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


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


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 = 

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'));

More About

expand all


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?