Main Content

coder.resize

调整 coder.Type 对象的大小

说明

示例

t_out = coder.resize(t,sz)t 的大小调整为 sz

示例

t_out = coder.resize(t,sz,variable_dims) 返回 coder.Type t 的修改副本,其大小(上界)为 sz,变量维度为 variable_dims。如果 variable_dimssz 是标量,该函数会将这些标量应用于 t 的所有维度。默认情况下,variable_dims 不应用于 sz01(表示固定)的维度。使用 'uniform' 选项可覆盖此特例。对于大小为 inf 的维度,coder.resize 函数会忽略 variable_dims。这些维度是可变大小。t 可以是元胞数组类型,在这种情况下,coder.resize 会调整元胞数组中所有元素的大小。

示例

t_out = coder.resize(t,[],variable_dims) t 更改为具有可变维度 variable_dims,同时保持大小不变。

示例

t_out = coder.resize(t,sz,variable_dims,Name,Value) 通过使用一个或多个名称-值对组参数指定的附加选项来调整 t 的大小。

示例

t_out = coder.resize(t,'sizelimits',limits) 根据 limits 向量中的阈值调整 t 的单个维度的大小。limits 向量是一个包含两个正整数元素的行向量。t 的每个维度都会根据 limits 向量中的阈值单独调整大小。

  • 当一个维度的大小 S 小于在 limits 中定义的两个阈值时,该维度保持不变。

  • 当一个维度的大小 S 大于或等于在 limits 中定义的第一个阈值且小于第二个阈值时,该维度将更改为具有可变大小且上界为 S

  • 但是,当一个维度的大小 S 也大于或等于在 limits 中定义的第二个阈值时,该维度将变为具有无界变量大小。

如果 limits 的值是标量,将对阈值进行标量扩展以表示两个阈值。例如,如果 limits 定义为 4,则会将它解释为 [4 4]

'sizelimits' 选项允许您在生成的代码中为大型数组动态分配内存。

示例

全部折叠

将固定大小数组更改为无界可变大小数组。

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

将固定大小数组更改为有界可变大小数组。

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

调整结构体字段的大小。

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

调整元胞数组的大小。

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

基于有界和无界阈值将固定大小数组更改为可变大小数组。

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

输入参数

全部折叠

由可变大小阈值组成的行向量。如果 limits 的值是标量,将对阈值进行标量扩展。如果 t 的一个维度的大小 sz 大于或等于在 limits 中定义的第一个阈值且小于第二个阈值,该维度将更改为具有可变大小且上界为 sz。如果 t 的一个维度的大小 sz 也大于或等于第二个阈值,该维度将变为具有无界变量大小。

但是,如果大小 sz 小于两个阈值,则该维度保持不变。

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

数据类型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

coder.Type 对象 t_out 的新大小

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

数据类型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

如果 tcoder.CellType 对象,则 coder.CellType 对象必须为同构对象。

示例: coder.resize(t,inf);

数据类型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | string | struct | table | cell | function_handle | categorical | datetime | duration | calendarDuration | fi
复数支持:

指定 t_out 的每个维度是固定大小还是可变大小。

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

数据类型: logical

名称-值参数

将可选的参数对组指定为 Name1=Value1,...,NameN=ValueN,其中 Name 是参数名称,Value 是对应的值。名称-值参数必须出现在其他参数后,但参数对组的顺序无关紧要。

在 R2021a 之前,使用逗号分隔每个名称和值,并用引号将 Name 引起来。

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

recursive 设置为 true 会调整 t 及其中包含的所有类型的大小。

数据类型: logical

uniform 设置为 true 会调整 t 的大小,并对大小为 1 的维度应用启发式方法。

启发式方法的工作方式如下:

  • 如果 variable_dims 是标量 true,则将所有维度的大小都调整为在 sz 中指定的上界变量大小。这包括大小为 1 的维度。例如:

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

    这将生成对象 tResize,如下所示:

    tResize = 
    
    coder.PrimitiveType
       :1×:7 double
    
        Edit Type Object
  • 如果使用 'sizelimits' 选项将 uniform 设置为 true,则会根据 'sizelimits' 启发式方法,将大小为 1 的维度也调整为可变大小。例如:

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

    这些命令会生成一个 tResize 对象,如下所示:

    tResize = 
    
    coder.PrimitiveType
       :1×:5 double
    
        Edit Type Object
  • 如果将 variable_dims 指定为非标量逻辑值,则 uniform 设置不起作用。但是,如果 variable_dims 是标量并且 uniform 设置为 false,则只会调整大于 1 的维度的大小。

数据类型: logical

sizelimits 选项与 limits 向量结合使用会调整 t 的各个维度的大小。

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

数据类型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

输出参数

全部折叠

调整大小后的 coder.Type 对象

数据类型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | string | struct | table | cell | function_handle | categorical | datetime | duration | calendarDuration | fi
复数支持:

限制

  • 对于稀疏矩阵,coder.resize 删除可变大小维度的上界。

版本历史记录

在 R2011a 中推出