create coder.type object to represent the type of an entry-凯发k8网页登录
create coder.type
object to represent the type
of an entry-point function input
syntax
description
note
you can also create and edit coder.type
objects
interactively by using the coder type editor. see .
creates an object that is derived from type_obj
= coder.typeof(v
)coder.type
to represent the type of v
for code generation. use
coder.typeof
to specify only input parameter types. use it with the codegen
function
-args
option or in a matlab®
coder™ project when you are defining an input type by providing a sample
code. do not use it in matlab code from which you intend to generate code.
returns a modified copy of type_obj
= coder.typeof(v
,sz
,variable_dims
)type_obj
=
coder.typeof(v
) with upper bound size specified by
sz
and variable dimensions specified by
variable_dims
.
examples
input arguments
output arguments
limitations
for sparse matrices,
coder.typeof
drops upper bounds for variable-size dimensions.for representing gpu arrays, only bounded numeric and logical base types are supported. scalar gpu arrays, structures, cell-arrays, classes, enumerated types, character, half-precision and fixed-point data types are not supported.
when using
coder.typeof
to represent gpu arrays, the memory allocation (malloc) mode property of the gpu code configuration object must be set to be'discrete'
.
tips
coder.typeof
fixes the size of a singleton dimension unless thevariable_dims
argument explicitly specifies that the singleton dimension has a variable size.for example, the following code specifies a 1-by-:10 double. the first dimension (the singleton dimension) has a fixed size. the second dimension has a variable size.
by contrast, this code specifies a :1-by-:10 double. both dimensions have a variable size.t = coder.typeof(5,[1 10],1)
t = coder.typeof(5,[1 10],[1 1])
note
for a matlab function block, singleton dimensions of input or output signals cannot have a variable size.
if you are already specifying the type of an input variable by using a type function, do not use
coder.typeof
unless you also want to specify the size. for instance, instead ofcoder.typeof(single(0))
, use the syntaxsingle(0)
.for cell array types,
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, classification as homogeneous or heterogeneous is ambiguous. for example, the type for {1 [2 3]} can be a 1x2 heterogeneous type where 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 coder.celltypemakehomogeneous
ormakeheterogeneous
methods to make a type with the classification that you want. themakehomogeneous
method makes a homogeneous copy of a type. themakeheterogeneous
method makes a heterogeneous copy of a type.the
makehomogeneous
andmakeheterogeneous
methods permanently assign the classification as heterogeneous and homogeneous. you cannot later use one of these methods to create a copy that has a different classification.during code generation with gpu array types, if one input to the entry-point function is of the gpu array type, then the output variables are all gpu array types, provided they are supported for gpu code generation. for example. if the entry-point function returns a
struct
and becausestruct
is not supported, the generated code returns a cpu output. however, if a supported matrix type is returned, then the generated code returns a gpu output.
version history
introduced in r2011a