coder.CellType - Represent set of MATLAB cell arrays - MATLAB (original) (raw)
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 thecodegen
-args
option. Do not pass as an input to a generated MEX function.
Creation
t = coder.typeof([cells](#mw%5Ff5768276-4e70-48e6-b152-81a100281503))
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](#mw%5Ff5768276-4e70-48e6-b152-81a100281503),[sz](#mw%5Ffb5d7ded-fd36-4007-8a84-2fab04b5c8f3),[variable_dims](#mw%5F8d899f11-063f-4e54-9380-445c69dafab7))
creates a coder.CellType
object that has upper bounds specified by sz
and variable dimensions specified byvariable_dims
. If sz
specifiesinf
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 not1
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](#mw%5Ff5768276-4e70-48e6-b152-81a100281503))
creates acoder.CellType
object for a cell array that has the cells and cell types specified by cells
. The cells incells
must be type objects.
t = coder.newtype('cell',[cells](#mw%5Ff5768276-4e70-48e6-b152-81a100281503),[sz](#mw%5Ffb5d7ded-fd36-4007-8a84-2fab04b5c8f3),[variable_dims](#mw%5F8d899f11-063f-4e54-9380-445c69dafab7))
creates a coder.CellType
that has upper bounds specified by sz
and variable dimensions specified byvariable_dims
. If sz
specifiesinf
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 not1
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
cells
— Specification of cell types
cell array
Cell array that specifies the cells and cell types for the output coder.CellType
object. Forcoder.typeof
, cells
can contain type objects or example values. For coder.newtype
,cells
must contain type objects.
sz
— Size of cell array
row vector of integer values
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]
.
variable_dims
— Dimensions that are variable size
row vector of logical values
Specifies whether each dimension is variable size (true) or fixed size (false).
For coder.newtype
, the default istrue
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
Alignment
— Run-time memory alignment
-1
| power of 2
that is less than or equal to128
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.
Cells
— Types of cells
cell array
A cell array that specifies the coder.Type
of each cell.
ClassName
— Name of class
character vector or string scalar
Class of values in this set.
Extern
— External definition
logical scalar
Specifies whether the cell array type is externally defined.
— Name of header file
nonempty character vector nonempty string scalar
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 thecodegen
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.
SizeVector
— Upper bounds of dimensions of cell array
row vector of integer values
Upper bounds of dimensions of the cell array, specified as a row vector of integer values
TypeName
— Name of generated structure type
character vector
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.
VariableDims
— Dimensions that are variable size
row vector of logical 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
Examples
Create a Type for a Cell Array Whose Elements Have the Same Class
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.
Create a Heterogeneous Type for a Cell Array Whose Elements Have the Same Class
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.
Create a Cell Array Type for a Cell Array Whose Elements Have Different Classes
Define variables that have different classes.
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.CellType 1x2 heterogeneous cell f0: 1x1 char f1: 1x1 double
Create a Type for a Variable-Size Homogeneous Cell Array from an Example Cell Array Whose Elements Have Different Classes
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 New Cell Array Type from a Cell Array of Types
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 byta
and ta
.
t = coder.newtype('cell',{ta,tb})
t =
coder.CellType 1x2 heterogeneous cell f0: 1x1 int8 f1: :1x:2 double
Create a coder.CellType
That Uses an Externally Defined Type
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 termslocked heterogeneous
orlocked homogeneous
indicate that the classification as homogeneous or heterogeneous is permanent. You cannot later change the classification by using themakeHomogeneous
ormakeHeterogeneous
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 a1x2
heterogeneous type. The first element is double and the second element is1x2
double. The type can also be a1x3
homogeneous type in which the elements have classdouble
and size1x:2
. For these ambiguous cases,coder.typeof
uses heuristics to classify the type as homogeneous or heterogeneous. If you want a different classification, use themakeHomogeneous
ormakeHeterogeneous
methods. ThemakeHomogeneous
method makes a homogeneous copy of a type. ThemakeHeterogeneous
method makes a heterogeneous copy of a type.
ThemakeHomogeneous
andmakeHeterogeneous
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