Skip to Main Content Skip to Search
Product Documentation

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.

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} = [];

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)

See Also

num2cell | ones | rand | randn | zeros

How To

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS