Main Content

本页翻译不是最新的。点击此处可查看最新英文版本。

输入设定

指定 MATLAB® 函数输入变量的属性以启用代码生成

要进行代码生成,您必须指定入口函数的输入变量的大小和类型。您可以指定输入类型:

  • 在您的 MATLAB 代码中,通过使用 arguments 块在入口函数中执行函数参量验证。如果使用 arguments 块指定输入类型,还可以使用 coder.mustBeComplex 等验证函数指定其他变量属性,包括输入数据是复数、稀疏还是 GPU 数组。

  • 使用 MATLAB Coder™

  • 在命令行中,对 codegen 命令使用 -args 参量。使用 -args 参量在命令行指定的输入类型可以使用 coderTypeEditor 或函数(如 coder.typeof)进行预配置。

  • 在您的 MATLAB 代码中,通过使用 assert 语句执行预条件。

App

MATLAB CoderMATLAB 代码生成 C 代码或 MEX 函数
coderTypeEditorLaunch the Coder Type Editor dialog (自 R2020a 起)

函数

全部展开

codegenMATLAB 代码生成 C/C++ 代码。
coder.getArgTypesDetermine types of function input arguments by executing test file
coder.newtypeCreate coder.Type object to represent type of an entry-point function input
coder.resize调整 coder.Type 对象的大小
coder.typeofCreate coder.Type object to represent the type of an entry-point function input
arguments声明函数参数验证 (自 R2019b 起)
coder.mustBeComplexValidate that value lies on the complex plane (自 R2023b 起)
coder.specifyAsGPUSpecify that value is a GPU input to an entry-point function for GPU code generation (自 R2023b 起)
coder.varsize声明可变大小数据
mustBeA验证值来自指定的类之一 (自 R2020b 起)
mustBeNonsparse验证值为非稀疏值
mustBeReal验证值是实数
mustBeSparseValidate that value is sparse (自 R2023b 起)
assert条件为 false 时引发错误

全部展开

coder.ArrayTypeRepresent set of MATLAB arrays acceptable for input specification
coder.CellTypeRepresent set of MATLAB cell arrays
coder.ClassTypeRepresent set of MATLAB classes acceptable for input specification
coder.ConstantSpecification of constant value for code generation
coder.EnumTypeRepresent set of MATLAB enumerations acceptable for input specification
coder.FiTypeRepresent set of MATLAB fixed-point arrays acceptable for input specification
coder.PrimitiveTypeRepresent set of logical, numeric, or character arrays acceptable for input specification
coder.StructTypeRepresent set of MATLAB structure arrays acceptable for input specification
coder.StringTypeRepresent set of MATLAB strings acceptable for input specification (自 R2022b 起)
coder.Type表示输入设定可接受的一组 MATLAB

对象

coder.OutputTypeOutput type from an entry-point function to specify as an input type

主题

输入设定基础知识

MATLAB 代码中指定输入类型

使用 MATLAB Coder 指定输入类型

在命令行指定输入类型

故障排除