coder.resize - Resize coder.Type object - MATLAB (original) (raw)
Syntax
Description
[t_out](#mw%5F82bf8f0e-e3da-4e8b-a06d-11845d3ad8ed) = coder.resize([t](#mw%5F6a685413-d763-4980-81db-073f941f849b),[sz](#mw%5F3bb292e9-a932-4f54-8b7a-c936594d6b31))
resizes t
to have size sz
.
[t_out](#mw%5F82bf8f0e-e3da-4e8b-a06d-11845d3ad8ed) = coder.resize([t](#mw%5F6a685413-d763-4980-81db-073f941f849b),[sz](#mw%5F3bb292e9-a932-4f54-8b7a-c936594d6b31),[variable_dims](#mw%5Fa6e08bc2-4b4d-40c6-9898-eb640d9d17cb))
returns a modified copy of coder.Type
t
with (upper-bound) size sz
and variable dimensionsvariable_dims
. If variable_dims
or sz
are scalars, the function applies the scalars to all dimensions of t
. By default, variable_dims
does not apply to dimensions where sz
is 0
or 1
, which are fixed. To override this default and allow dimensions of size 0
and1
to vary, set the uniform
argument totrue
. The coder.resize
function ignoresvariable_dims
for dimensions with size inf
, as these dimensions are variable size by definition. If t
is a cell array of types,coder.resize
resizes all elements of the cell array.
[t_out](#mw%5F82bf8f0e-e3da-4e8b-a06d-11845d3ad8ed) = coder.resize([t](#mw%5F6a685413-d763-4980-81db-073f941f849b),[],[variable_dims](#mw%5Fa6e08bc2-4b4d-40c6-9898-eb640d9d17cb))
allows the dimensions of t
specified by variable_dims
to vary without changing the size of t
.
[t_out](#mw%5F82bf8f0e-e3da-4e8b-a06d-11845d3ad8ed) = coder.resize(___,[Name=Value](#namevaluepairarguments))
specifies resizing options using one or more name-value arguments in addition to the input arguments in previous syntaxes. For example, to recursively resize t
and all types within t
, setrecursive
to true
.
Examples
Change Fixed-Size Array to Unbounded, Variable-Size Array
Create a fixed-size 3x3
array using coder.typeof.
T = coder.typeof(ones(3,3))
T =
coder.PrimitiveType 3×3 double
Change T
to an unbounded, variable-size array. The code generator uses a colon prefix (:
) to denote a variable-size dimension.
T =
coder.PrimitiveType :inf×:inf double
Change Fixed-Size Array to Bounded, Variable-Size Array
Create a fixed-size 3x3
array using coder.typeof.
T = coder.typeof(ones(3,3))
T =
coder.PrimitiveType 3×3 double
Change T
to a bounded, variable-size array, with upper bounds of4
and 5
. The code generator uses a colon prefix (:
) to denote a variable-size dimension.
T = coder.resize(T,[4 5],true)
T =
coder.PrimitiveType :4×:5 double
Change Specific Dimensions of Fixed-Size Array to Variable-Size
Create a fixed-size 3x3x3x3
array using coder.typeof.
T = coder.typeof(ones(3,3,3,3))
T =
coder.PrimitiveType 3×3×3×3 double
Modify T such that the first and fourth dimensions are variable-size, while the second and third dimensions remain fixed-size. The code generator uses a colon prefix (:
) to denote a variable-size dimension.
coder.resize(T,[],[true false false true])
ans =
coder.PrimitiveType :3×3×3×:3 double
Recursively Resize Structure Fields
Create a 1x1
struct
containing two fields: f1
, a3x3
array, and f2
, a 4x4
array.
T = coder.typeof(struct('f1',zeros(3,3),'f2',ones(4,4)))
T =
coder.StructType 1×1 struct f1: 3×3 double f2: 4×4 double
Recursively change T
and all fields of T
to 5x5
arrays.
coder.resize(T,[5,5],recursive=true))
ans =
coder.StructType 5×5 struct a: 5×5 double b: 5×5 double
Force Variable-Sizing of Fixed-Size Dimensions
Use the uniform=true
option to force the code generator to treat dimensions of size 0
or 1
, which are fixed by default, as variable-size.
Create a fixed-size 3x1x4
array using coder.typeof, and force the code generator to allow all dimensions to vary in size. The code generator uses a colon prefix (:
) to denote a variable-size dimension.
T = coder.typeof(ones(3,1,4)); T = coder.resize(T,[],true,uniform=true)
T =
coder.PrimitiveType :3×:1×:4 double
Set Size-Dependent Upper Bounds
Use the sizelimits=[min max]
option to set upper bounds for array dimensions.
Create a fixed-size 5x10x20
array using coder.typeof.
T = coder.typeof(ones(5,10,20))
T =
coder.PrimitiveType 5×10×20 double
Resize T
with the sizelimits
minimum set to7
and the maximum set to 15
.coder.resize
does not modify dimensions with size less than 7, sets dimensions with size between 7 and 15 to bounded variable-size, and sets dimensions with size greater than 15 to unbounded. The code generator uses a colon prefix (:
) to denote a variable-size dimension.
T = coder.resize(T,[],sizelimits=[7,15])
T =
coder.PrimitiveType 5×:10×:inf double
Input Arguments
t
— Object to be resized
coder.Type
object
Object to be resized, specified as a coder.Type
object. Ift
is a coder.CellType
object, thecoder.CellType
object must be homogeneous.
Example: coder.resize(T,inf);
Data Types: coder.CellType
| coder.ClassType
| coder.Constant
| coder.EnumType
| coder.FiType
| coder.OutputType
| coder.PrimitiveType
| coder.StructType
sz
— New size
scalar integer | row vector of integers
New size for the coder.Type
object, specified as a scalar integer or a row vector of integers.
Example: coder.resize(T,[3,4]);
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
variable_dims
— Variable dimensions
scalar logical value | row vector of logical values
Variable dimensions of the coder.Type
object, specified as a scalar logical or row vector of logical values. If variable_dims
is scalar,variable_dims
applies to all dimensions of the coder.Type
object.
Example: coder.resize(T,[4,5],[true false]);
Data Types: logical
Name-Value Arguments
Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN
, where Name
is the argument name and Value
is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.
Example: coder.resize(T,[5,5],recursive=true)
recursive
— Recursively resize
false (default) | true
Recursively resize the coder.Type
object and all types contained within it, specified asfalse
or true
.
Data Types: logical
uniform
— Force variable-sizing
false (default) | true
Force variable-sizing of all dimensions of thecoder.Type
object, specified as false
ortrue
. If you do not set uniform
totrue
, dimensions of size 0
and 1
will remain fixed-size, even if variable_dims
is set totrue
. However, if you specify variable_dims
as a nonscalar logical vector, the uniform
setting has no effect.
Example: coder.resize(T,[1,7],true,uniform=true)
Data Types: logical
sizelimits
— Minimum and maximum dimensions
row vector of at most two integer values
Minimum and maximum dimensions of the coder.Type
object, specified as a row vector of at most two integer values.
- If
sizelimits
has two elements, then these values correspond to[min max]
, wheremax
must be greater than or equal tomin
- If
sizelimits
has one element, thenmin
andmax
are both set to that value
For each dimension of the coder.Type
object with sizes
:
- If
s
is greater than or equal tomax
, the code generator changes the dimension to unbounded variable-size (:inf
) - If
s
is greater than or equal tomin
and less thanmax
, the code generator changes the dimension to variable-size with an upper bound ofs
(:s
) - If
s
is less thanmin
, the code generator does not modify the dimension
Example: coder.resize(T,[],sizelimits=[5,20])
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Output Arguments
t_out
— Resized type object
coder.Type object
Resized coder.Type
object
Data Types: coder.CellType
| coder.ClassType
| coder.Constant
| coder.EnumType
| coder.FiType
| coder.OutputType
| coder.PrimitiveType
| coder.StructType
Limitations
- For sparse matrices,
coder.resize
drops the upper bounds for variable-size dimensions.
Version History
Introduced in R2011a