Main Content

coder.CellType Class

Namespace: coder
Superclasses: coder.ArrayType

Represent set of MATLAB cell arrays

Description

Specifies the set of cell arrays that the generated code accepts. Use only with the fiaccel -args option. Do not pass as an input to a generated MEX function.

Creation

Note

You can also create and edit coder.Type objects interactively by using the Coder Type Editor. See Create and Edit Input Types by Using the Coder Type Editor.

t = coder.typeof(cells) creates a coder.CellType object for a cell array that has the same cells and cell types as cells. The cells in cells are type objects or example values.

t = coder.typeof(cells,sz,variable_dims) creates a coder.CellType object that has upper bounds specified by sz and variable dimensions specified by variable_dims. If sz specifies inf for a dimension, then the size of the dimension is unbounded and the dimension is variable size. When sz is [], the upper bounds do not change. If you do not specify the variable_dims input parameter, except for the unbounded dimensions, the dimensions of the type are fixed. A scalar variable_dims applies to the bounded dimensions that are not 1 or 0.

When cells specifies a cell array whose elements have different classes, you cannot use coder.typeof to create a coder.CellType object for a variable-size cell array.

t = coder.newtype('cell',cells) creates a coder.CellType object for a cell array that has the cells and cell types specified by cells. The cells in cells must be type objects.

t = coder.newtype('cell',cells,sz,variable_dims) creates a coder.CellType that has upper bounds specified by sz and variable dimensions specified by variable_dims. If sz specifies inf for a dimension, then the size of the dimension is unbounded and the dimension is variable size. When sz is [], the upper bounds do not change. If you do not specify the variable_dims input parameter, except for the unbounded dimensions, the dimensions of the type are fixed. A scalar variable_dims applies to the bounded dimensions that are not 1 or 0.

When cells specifies a cell array whose elements have different classes, you cannot use coder.newtype to create a coder.CellType object for a variable-size cell array.

Input Arguments

expand all

Cell array that specifies the cells and cell types for the output coder.CellType object. For coder.typeof, cells can contain type objects or example values. For coder.newtype, cells must contain type objects.

Specifies the upper bound for each dimension of the cell array type object. For coder.newtype, sz cannot change the number of cells for a heterogeneous cell array.

For coder.newtype, the default is [1 1].

Specifies whether each dimension is variable size (true) or fixed size (false).

For coder.newtype, the default is true for dimensions for which sz specifies an upper bound of inf and false for all other dimensions.

When cells specifies a cell array whose elements have different classes, you cannot create a coder.CellType object for a variable-size cell array.

Properties

expand all

A cell array that specifies the coder.Type of each cell.

Class of values in this set.

Upper bounds of dimensions of the cell array, specified as a row vector of integer values

Dimensions of the cell array that are variable-size, specified as a row vector of logical values. If a vector element is true, the corresponding dimension is variable-size.

Methods

expand all

Examples

collapse all

Create a type for a cell array whose elements are all of class double.

t = coder.typeof({1 2 3})
t = 

coder.CellType
   1x3 homogeneous cell 
      base: 1x1 double

The type is homogeneous.

To create a heterogeneous type when the elements of the example cell array type have the same class, use the makeHeterogeneous method.

t = coder.typeof({1 2 3});
t.makeHeterogeneous
t = 

coder.CellType
   1×3 locked heterogeneous cell 
      f1: 1×1 double
      f2: 1×1 double
      f3: 1×1 double

The cell array type is heterogeneous. It is represented as a structure in the generated code.

Define variables that have different classes.

a = 'a';
b = 1;

Pass the example cell values to coder.typeof. The first element of the created type has class char and the second element has class double.

t = coder.typeof({a, b})
t = 

coder.CellType
   1x2 heterogeneous cell 
      f0: 1x1 char
      f1: 1x1 double

Create a type for a cell array that contains two character vectors that have different sizes.

t = coder.typeof({'aa', 'bbb'})
t = 

coder.CellType
   1x2 heterogeneous cell 
      f0: 1x2 char
      f1: 1x3 char

The cell array type is heterogeneous.

Create a type using the same cell array input. This time, specify that the cell array type has variable-size dimensions.

t = coder.typeof({'aa','bbb'},[1,10],[0,1])
t = 

coder.CellType
   1×:10 locked homogeneous cell 
      base: 1×:3 char

The cell array type is homogeneous. coder.typeof determined that the base type 1x:3 char can represent 'aa', and 'bbb'.

Create a type for a scalar int8.

ta = coder.newtype('int8',[1 1]);

Create a type for a :1x:2 double row vector.

tb = coder.newtype('double',[1 2],[1 1]);

Create a cell array type whose cells have the types specified by ta and ta.

t = coder.newtype('cell',{ta,tb})
t = 

coder.CellType
   1x2 heterogeneous cell 
      f0: 1x1 int8
      f1: :1x:2 double

Tips

  • In the display of a coder.CellType object, the terms locked heterogeneous or locked homogeneous indicate that the classification as homogeneous or heterogeneous is permanent. You cannot later change the classification by using the makeHomogeneous or makeHeterogeneous methods.

  • coder.typeof determines whether the cell array type is homogeneous or heterogeneous. If the cell array elements have the same class and size, coder.typeof returns a homogeneous cell array type. If the elements have different classes, coder.typeof returns a heterogeneous cell array type. For some cell arrays, the classification as homogeneous or heterogeneous is ambiguous.

    For example, the type for {1 [2 3]} can be a 1x2 heterogeneous type. The first element is double and the second element is 1x2 double. The type can also be a 1x3 homogeneous type in which the elements have class double and size 1x:2. For these ambiguous cases, coder.typeof uses heuristics to classify the type as homogeneous or heterogeneous. If you want a different classification, use the makeHomogeneous or makeHeterogeneous methods. The makeHomogeneous method makes a homogeneous copy of a type. The makeHeterogeneous method makes a heterogeneous copy of a type.

    The makeHomogeneous and makeHeterogeneous methods permanently assign the classification as homogeneous and heterogeneous, respectively. You cannot later use one of these methods to create a copy that has a different classification.

  • Value. To learn how value classes affect copy operations, see Copying Objects.

Version History

Introduced in R2015b