Main Content

coder.resize

Resize coder.Type object

Description

example

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. Use the 'uniform' option to override this special case. The coder.resize function ignores variable_dims for dimensions with size inf. These dimensions are variable size. t can be a cell array of types, in which case, coder.resize resizes all elements of the cell array.

example

t_out = coder.resize(t,[],variable_dims) changes t to have variable dimensions variable_dims while leaving the size unchanged.

example

t_out = coder.resize(t,sz,variable_dims,Name,Value) resizes t by using additional options specified by one or more Name, Value pair arguments.

example

t_out = coder.resize(t,'sizelimits',limits) resizes the individual dimensions of t based on the threshold values in the limits vector. The limits vector is a row vector containing two positive integer elements. Each dimension of t is individually resized according to the thresholds in the limits vector.

  • When the size S of a dimension is lesser than both thresholds defined in limits, the dimension remains the same.

  • When the size S of a dimension is greater than or equal to the first threshold and less than the second threshold defined in limits, the dimension becomes variable size with upper bound S.

  • However, when the size S of a dimension is also greater than or equal to the second threshold defined in limits, the dimension becomes an unbounded variable size.

If the value of limits is scalar, the threshold gets scalar-expanded to represent both thresholds. For example, if limits is defined as 4, it is interpreted as [4 4].

The 'sizelimits' option allows you to dynamically allocate memory to large arrays in your generated code.

Examples

collapse all

Change a fixed-size array to an unbounded, variable-size array.

t = coder.typeof(ones(3,3))     
t = 

coder.PrimitiveType
   3×3 double
coder.resize(t,inf)           
ans = 

coder.PrimitiveType
   :inf×:inf double
% ':' indicates variable-size dimensions

Change a fixed-size array to a bounded, variable-size array.

t = coder.typeof(ones(3,3))
t = 

coder.PrimitiveType
   3×3 double
coder.resize(t,[4 5],1)
ans = 

coder.PrimitiveType
   :4×:5 double
% ':' indicates variable-size dimensions

Resize a structure field.

ts = coder.typeof(struct('a',ones(3, 3))) 
ts = 

coder.StructType
   1×1 struct
      a: 3×3 double
coder.resize(ts,[5, 5],'recursive',1)   
ans = 

coder.StructType
   5×5 struct
      a: 5×5 double

Resize a cell array.

tc = coder.typeof({1 2 3}) 
tc = 

coder.CellType
   1×3 homogeneous cell 
      base: 1×1 double
coder.resize(tc,[5, 5],'recursive',1)   
ans = 

coder.CellType
   5×5 homogeneous cell 
      base: 1×1 double

Change a fixed-sized array to a variable size based on bounded and unbounded thresholds.

t = coder.typeof(ones(100,200))
t = 

coder.PrimitiveType
   100×200 double
coder.resize(t,'sizelimits',[99 199])   
ans = 

coder.PrimitiveType
   :100×:inf double
% ':' indicates variable-size dimensions

Input Arguments

collapse all

A row vector of variable-size thresholds. If the value of limits is scalar, the threshold gets scalar-expanded. If the size sz of a dimension of t is greater than or equal to the first threshold and less than the second threshold defined in limits, the dimension becomes variable size with upper bound sz. If the size sz of a dimension of t is also greater than or equal to the second threshold, the dimension becomes an unbounded variable size.

However, if the size sz is lesser than both thresholds, the dimension remains the same.

Example: coder.resize(t,'sizelimits',[99 199]);

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

New size for coder.Type object, t_out

Example: coder.resize(t,[3,4]);

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

If t is a coder.CellType object, the coder.CellType object must be homogeneous.

Example: coder.resize(t,inf);

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | string | struct | table | cell | function_handle | categorical | datetime | duration | calendarDuration | fi
Complex Number Support: Yes

Specify whether each dimension of t_out is fixed size or variable size.

Example: coder.resize(t,[4 5],1);

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.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: coder.resize(t,[5, 5],'recursive', 1);

Setting recursive to true resizes t and all types contained within it.

Data Types: logical

Setting uniform to true resizes t and applies the heuristic for dimensions of size one.

The heuristic works in the following manner:

  • If variable_dims is a scalar true, all dimensions are resized to upper bound variable sizes specified in sz. This includes dimensions of size one. For example:

    t = coder.typeof(1, [1 5]);
    tResize = coder.resize(t,[1 7],true,'uniform',true); 

    This generates an object tResize as shown:

    tResize = 
    
    coder.PrimitiveType
       :1×:7 double
    
        Edit Type Object
  • If you set uniform to true with the 'sizelimits' option, the dimensions of size one are also resized to variable size, according to the 'sizelimits' heuristics. For example:

    t = coder.typeof(1, [1 5]);
    tResize = coder.resize(t,[],'sizelimits',[0 6],'uniform',true); 

    These commands generate an object tResize as shown:

    tResize = 
    
    coder.PrimitiveType
       :1×:5 double
    
        Edit Type Object
  • If variable_dims is specified as a non-scalar logical, the uniform setting has no effect. However, if variable_dims is scalar and uniform is set to false, only dimensions of size greater than one are resized.

Data Types: logical

Using the sizelimits options with limits vector resizes individual dimensions of t.

t = coder.typeof(1, [1 5]);
tResize = coder.resize(t,[],'sizelimits',[0 6],'uniform',true); 

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output Arguments

collapse all

Resized coder.Type object

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | string | struct | table | cell | function_handle | categorical | datetime | duration | calendarDuration | fi
Complex Number Support: Yes

Limitations

  • For sparse matrices, coder.resize drops the upper bounds for variable-size dimensions.

Version History

Introduced in R2011a