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 codegen -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

The run-time memory alignment of structures of this type in bytes. If you have an Embedded Coder® license and use Code Replacement Libraries (CRLs), the CRLs provide the ability to align data objects passed into a replacement function to a specified boundary. You can take advantage of target-specific function implementations that require data to be aligned. By default, the structure is not aligned on a specific boundary, so it is not matched by CRL functions that require alignment.

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

Class of values in this set.

Specifies whether the cell array type is externally defined.

If the cell array type is externally defined, the name of the header file that contains the external definition of the type, for example, 'mytype.h'. If you use the codegen command to specify the path to the file, use the -I option. If you use the MATLAB® Coder™ app to specify the path to the file, use the Additional include directories setting in the Custom Code tab in the project settings dialog box.

By default, the generated code contains #include statements for custom header files after the standard header files. If a standard header file refers to the custom structure type, then the compilation fails. If you specify the HeaderFile option, the code generator includes the custom header file where it is required.

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

Name to use in the generated code for the structure type that represents this cell array type, specified as a character vector. TypeName applies only to heterogeneous cell arrays types.

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

Create a cell type for a heterogeneous cell array.

ca = coder.typeof(double(0));
cb = coder.typeof(single(0));
t = coder.typeof({ca cb})
coder.CellType
   1x2 heterogeneous cell 
      f0: 1x1 double
      f1: 1x1 single

Use coder.cstructname to specify the name for the type and that the type is defined in an external file.

t = coder.cstructname(t,'mytype','extern','HeaderFile','myheader.h')
t = 

coder.CellType
   1×2 extern locked heterogeneous cell mytype(myheader.h) [-1] 
      f1: 1×1 double
      f2: 1×1 single

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