定义表输入
您可以在命令行中定义表输入。不支持通过使用预条件(assert 语句)以编程方式指定表输入类型。
在命令行中定义表输入
使用以下过程之一:
或者,如果您有使用示例输入调用入口函数的测试文件,您可以使用 coder.getArgTypes 来确定输入类型。
提供示例表输入
使用 -args 选项:
T = table(A,B,C,'VariableNames',vnames); fiaccel myFunction -args {T}
提供表类型
要为 fiaccel 提供一种表类型,请执行以下操作:
定义一个表。例如:
T = table(A,B,C,'VariableNames',vnames);从
T创建一个类型。t = coder.typeof(T);
通过使用
-args选项将类型传递给fiaccel。fiaccel myFunction -args {t}
提供常量表输入
要指定表输入为常量,请使用 coder.Constant 和 -args 选项:
T = table(A,B,C,'VariableNames',vnames); fiaccel myFunction -args {coder.Constant(T)}
表的表示
表的代码生成器类型对象描述对象及其属性。使用 coder.typeof (MATLAB Coder) 或将 table 作为字符串标量传递给 coder.newtype (MATLAB Coder)。
代码生成器生成类型对象显示对象属性的简洁描述,同时排除内部状态值。非常量属性显示其类型和大小,而常量属性只显示其值。例如:
A = [1 2 3]'; B = [4 5 6]'; C = [7 8 9]'; t = table(A,B,C); tType = coder.typeof(t)
变量 t 的表示存储在代码生成器生成类型对象 tType 中。
tType =
matlab.coder.type.TableType
3x3 table
Data : 1x3 homogeneous cell
Description : 1x0 char
UserData : 0x0 double
DimensionNames : {'Row'} {'Variables'}
VariableNames : {'A'} {'B'} {'C'}
VariableDescriptions : 1x3 homogeneous cell
VariableUnits : 1x3 homogeneous cell
VariableContinuity : 1x3 matlab.internal.coder.tabular.Continuity
RowNames : 0x0 homogeneous cell如果您的工作流需要代码生成器生成类型对象的旧表示,请对具有您的类或对象的新表示的变量使用 getCoderType 函数。请参阅。
使用 coder.resize 调整对象属性的大小
您可以使用 coder.resize (MATLAB Coder) 调整大多数对象的大小。您可以调整对象及其属性的大小,并在属性中创建数组。
对于一个 table 代码生成器对象,您可以调整对象属性的大小:
A = [1 2 3]'; B = [4 5 6]'; C = [7 8 9]'; t = table(A,B,C); tType = coder.typeof(t) tType.Description = coder.resize(tType.Description,[1 12],[0 1])
以下代码将 Description 属性的大小调整为 1x:12 char 属性,后者的上界为 12。
tType =
matlab.coder.type.TableType
3x3 table
Data : 1x3 homogeneous cell
Description : 1x:12 char
UserData : 0x0 double
DimensionNames : {'Row'} {'Variables'}
VariableNames : {'A'} {'B'} {'C'}
VariableDescriptions : 1x3 homogeneous cell
VariableUnits : 1x3 homogeneous cell
VariableContinuity : 1x3 matlab.internal.coder.tabular.Continuity
RowNames : 0x0 homogeneous cell您也可以使用 coder.resize 调整对象的大小。请参阅。
另请参阅
table | coder.Constant (MATLAB Coder) | coder.typeof (MATLAB Coder)