将对象传递给coder.typeof
或将类名作为字符串标量传递给coder.newtype
创建一个对象,该对象表示用于代码生成的对象类型。
编码器类型对象显示对象属性的简洁描述,同时排除内部状态值。非常量属性显示它们的类型和大小,而常量属性只显示它们的值。
要创建编码器类型对象,请将兼容对象传递给coder.typeof
.例如:
t =分类({“r”,‘g’,“b”});式= coder.typeof (t)
变量的表示t
是否存储在编码器类型对象中式
.
tType = matlab.code .type. categoricaltype 1x3 category Categories: 3x1 homogeneous cell序号:1x1 logical Protected: 1x1 logical . tType = matlab.code .type. categoricaltype 1x3 category Categories: 3x1 homogeneous cell序号:1x1 logical
您可以编辑编码器类型对象的属性。可以将标量值分配给对象属性。值被赋给编码器类型对象属性时,会隐式转换为相应的编码器类型值。代码生成器隐式地将分配给编码器类型对象属性的常量转换为编码器。常数
值。你可以调整对象本身的大小
coder.resize
您可以使用coder.resize
.您可以调整对象的大小,它的属性,并在属性中创建数组。
例如,对于a时间表
Coder对象,您可以调整对象的大小:
t =时间表((1:5),(15),“SampleRate”1);式= coder.typeof (t);式=编码器。resize(tType, [10 2],[10 0])
此代码调整时间表
到一个: 10 x2
对象。
tType = matlab.code .type. regulartimetabletype:10x2 schedule Data: 1x2 homogeneous cell Description: 1x0 char UserData: 0x0 double DimensionNames: {'Time'} {'Variables'} VariableNames: {'Var1'} {'Var2'} VariableDescriptions: 1x2 homogeneous cell VariableUnits: 1x2 homogeneous cell variabcontinuity:1x2 matlab.internal.code .tabular. continuity StartTime: 1x1 matlab.code .type. durationtype SampleRate: 1x1 double TimeStep: 1x1 matlab.code .type. durationtype . duration
的常数性质式
显示他们的价值观。非常量属性只显示它们的类型和大小。
请注意
并不是所有的类型都代表MATLAB®类与coder.resize
.
您可以通过编辑属性本身来调整对象的大小。对于一个持续时间
编码器类型对象x
,编辑大小
属性以根据需要更改大小。
x = coder.typeof(持续时间((1:3),0,0));[10 10]
此代码更改编码器类型对象的大小。
x = matlab.code .type. durationtype 10x10 duration格式:1x8 char
属性也可以使编码器类型对象变量大小VarDims
国旗:
x.VarDims (2) = true
编码器类型对象的第2维的上界为10
.
x = matlab.code .type. durationtype 10x:10 duration格式:1x8 char
在R2021a,称coder.typeof
不再返回a编码器。ClassType
对象。如果您的工作流需要编码器类型对象的遗留表示形式,请使用getCoderType
函数调用具有类或对象新表示形式的变量。例如,要获取datetime
变量,使用具有新表示的变量tt
调用getCoderType
功能:
t = datetime;tt = coder.typeof (t);ttLegacy = tt.getCoderType ()
在“编码器类型编辑器”中,代码生成器包含该函数getCoderType
用于编码器类型对象。使用此函数可返回编码器类型的遗留表示形式。看到的,使用编码器类型编辑器创建和编辑输入类型
某些MATLAB数据类型为MATLAB代码生成提供定制的类型表示。在其他情况下,类型使用编码器。ClassType
.