Main Content

coder.resize

Resize coder.Type object

Description

t_out = coder.resize(t,sz) resizes t to have size sz.

example

t_out = coder.resize(t,sz,variable_dims) returns a modified copy of coder.Type t with (upper-bound) size sz and variable dimensions variable_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 and 1 to vary, set the uniform argument to true. The coder.resize function ignores variable_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.

example

t_out = coder.resize(t,[],variable_dims) allows the dimensions of t specified by variable_dims to vary without changing the size of t.

example

t_out = coder.resize(___,Name=Value) 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, set recursive to true.

example

Examples

collapse all

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.resize(T,inf)           
T = 

coder.PrimitiveType
   :inf×:inf double

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 of 4 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

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

Create a 1x1 struct containing two fields: f1, a 3x3 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

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

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

collapse all

Object to be resized, specified as a coder.Type object. If t is a coder.CellType object, the coder.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

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 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 as Name1=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)

Recursively resize the coder.Type object and all types contained within it, specified as false or true.

Data Types: logical

Force variable-sizing of all dimensions of the coder.Type object, specified as false or true. If you do not set uniform to true, dimensions of size 0 and 1 will remain fixed-size, even if variable_dims is set to true. 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

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], where max must be greater than or equal to min

  • If sizelimits has one element, then min and max are both set to that value

For each dimension of the coder.Type object with size s:

  • If s is greater than or equal to max, the code generator changes the dimension to unbounded variable-size (:inf)

  • If s is greater than or equal to min and less than max, the code generator changes the dimension to variable-size with an upper bound of s (:s)

  • If s is less than min, 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

collapse all

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