coder.varsize(
'var1'
, 'var2'
,
...)
coder.varsize('var1'
, 'var2'
,
..., ubound
)
coder.varsize('var1'
, 'var2'
,
..., ubound
, dims
)
coder.varsize('var1'
, 'var2'
,
..., []
, dims
)
coder.varsize(
declares one or more variables as variable-size data,
allowing subsequent assignments to extend their size. Each 'var1'
, 'var2'
,
...)'varn'
is
the name of a variable or structure field enclosed in quotes. If the
structure field belongs to an array of structures, use colon (:
)
as the index expression to make the field variable-size for all
elements of the array. For example, the expression coder.varsize('data(:).A')
declares
that the field A
inside each element of data
is
variable sized.
coder.varsize(
declares one or
more variables as variable-size data with an explicit upper bound
specified in 'var1'
, 'var2'
,
..., ubound
)ubound
. The argument ubound
must
be a constant, integer-valued vector of upper bound sizes for every
dimension of each 'varn'
.
If you specify more than one 'varn'
,
each variable must have the same number of dimensions.
coder.varsize(
declares
one or more variables as variable size with an explicit upper bound
and a mix of fixed and varying dimensions specified in 'var1'
, 'var2'
,
..., ubound
, dims
)dims
.
The argument dims
is a logical vector,
or double vector containing only zeros and ones. Dimensions that correspond
to zeros or false
in dims
have
fixed size; dimensions that correspond to ones or true
vary
in size. If you specify more than one variable, each fixed dimension
must have the same value across all 'varn'
.
coder.varsize(
declares
one or more variables as variable size with a mix of fixed and varying
dimensions. The empty vector 'var1'
, 'var2'
,
..., []
, dims
)[]
means that you
do not specify an explicit upper bound.
When you do not specify ubound
,
the upper bound is computed for each 'varn'
in
generated code.
When you do not specify dims
,
dimensions are assumed to be variable except the singleton ones. A
singleton dimension is a dimension for which size
(A,dim)
=
1.
You must add the coder.varsize
declaration
before each 'varn'
is
used (read). You can add the declaration before the first assignment
to each 'varn'
.
However, for a cell array element, the coder.varsize
declaration
must follow the first assignment to the element. For example:
... x = cell(3, 3); x{1} = [1 2]; coder.varsize('x{1}'); ...
You cannot use coder.varsize
outside the MATLAB® code
intended for code generation. For example, the following code does
not declare the variable, var
, as variable-size
data:
coder.varsize('var',10); codegen -config:lib MyFile -args var
Instead, include the coder.varsize
statement
inside MyFile
to declare var
as
variable-size data. Alternatively,
you can use coder.typeof
to declare var
as
variable-size outside MyFile
. It can then be passed
to MyFile
during code generation using the -args
option.
For more information, see coder.typeof
.
If you use the cell function to create a cell
array,
you cannot use coder.varsize
with that cell array.
If you use coder.varsize
with
a cell array element, the coder.varsize
declaration
must follow the first assignment to the element. For example:
... x = cell(3, 3); x{1} = [1 2]; coder.varsize('x{1}'); ...
You cannot use coder.varsize
with
a cell array input that is heterogeneous.
You cannot use coder.varsize
with
global variables.
You cannot use coder.varsize
with MATLAB class
properties.