# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.

# cell

## Description

A cell array is a data type with indexed data containers called cells, where each cell can contain any type of data. Cell arrays commonly contain either lists of text, combinations of text and numbers, or numeric arrays of different sizes. Refer to sets of cells by enclosing indices in smooth parentheses, `()`. Access the contents of cells by indexing with curly braces, `{}`.

## Creation

When you have data to put into a cell array, create the array using the cell array construction operator, `{}`.

```C = {1,2,3; 'text',rand(5,10,2),{11; 22; 33}} ```
```C = 2x3 cell array {[ 1]} {[ 2]} {[ 3]} {'text'} {5x10x2 double} {3x1 cell} ```

You also can use `{}` to create an empty 0-by-0 cell array.

```C = {} ```
```C = 0x0 empty cell array ```

To create a cell array with a specified size, use the `cell` function, described below.

You can use `cell` to preallocate a cell array to which you assign data later. `cell` also converts certain types of Java®, .NET, and Python® data structures to cell arrays of equivalent MATLAB® objects.

### Syntax

``C = cell(n)``
``C = cell(sz1,...,szN)``
``C = cell(sz)``
``D = cell(obj)``

### 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, .NET `System.String` or `System.Object` array, or Python sequence into a MATLAB cell array.```

### Input Arguments

expand all

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`

Sizes of the dimensions of the cell array, specified as 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`

Size, specified as a row vector of integers. Each element of `sz` 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`

Input array, specified as:

• Java array or object

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

• Python sequence type

### Output Arguments

expand all

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

Converted array, returned as a cell array.

Each cell contains a MATLAB object that has a type closest to the corresponding Java, .NET, or Python type. For more information, see:

## Examples

expand all

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

`C = cell(3)`
```C = 3x3 cell array {0x0 double} {0x0 double} {0x0 double} {0x0 double} {0x0 double} {0x0 double} {0x0 double} {0x0 double} {0x0 double} ```

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

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

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 = 3x2 cell array {0x0 double} {0x0 double} {0x0 double} {0x0 double} {0x0 double} {0x0 double} ```

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

`C = cell(size(A));`

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' ```

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] ```

## Tips

• Creating a cell array of empty matrices with the `cell` function is equivalent to assigning an empty matrix to the last index of a new cell array. For example, these two statements are equivalent:

```C = cell(3,4,2); C{3,4,2} = [];```

## Extended Capabilities

#### Introduced before R2006a

Was this topic helpful?

#### The Manager's Guide to Solving the Big Data Conundrum

Download white paper