输入设定
指定 MATLAB® 函数输入变量的属性以启用代码生成
要进行代码生成,您必须指定入口函数的输入变量的大小和类型。您可以指定输入类型:
在您的 MATLAB 代码中,通过使用
arguments块在入口函数中执行函数参量验证。如果使用arguments块指定输入类型,还可以使用coder.mustBeComplex等验证函数指定其他变量属性,包括输入数据是复数、稀疏还是 GPU 数组。使用 MATLAB Coder™。
在命令行中,对
codegen命令使用-args参量。使用-args参量在命令行指定的输入类型可以使用coderTypeEditor或函数(如coder.typeof)进行预配置。在您的 MATLAB 代码中,通过使用
assert语句执行预条件。
App
| MATLAB Coder | 从 MATLAB 代码生成 C 代码或 MEX 函数 |
函数
类
对象
coder.OutputType | Output type from an entry-point function to specify as an input type |
主题
输入设定基础知识
- 指定入口函数输入的类型
如何及为何执行输入类型设定。 - Specify Number of Input or Output Arguments to Entry-Point Functions
Control the number of input or output arguments in the generated code. - Specify Value Class Objects as Inputs
Specify that an entry-point input is an object of a value class.
在 MATLAB 代码中指定输入类型
- Use Function Argument Validation to Specify Entry-Point Input Types
Specify the types of the entry-point function inputs using anargumentsblock. - Specify Input Types Using assert Statements in MATLAB Code
Specify the types of entry-point function inputs by using theassertfunction.
使用 MATLAB Coder 指定输入类型
- Define Types of Entry-Point Inputs by Using the MATLAB Coder App
Specify the types of entry-point function inputs using the MATLAB Coder app. - Define Global Variables in the MATLAB Coder App
Use the MATLAB Coder app to specify the types and initial values of global variables that your MATLAB code uses.
在命令行指定输入类型
- Specify Input Types at the Command Line
Specify entry-point function input type by using the-argsoption. - Create and Edit Input Types by Using the Coder Type Editor
Define and editcoder.Typeobjects interactively. - Pass an Entry-Point Function Output as an Input
Simplify input type specification for multiple entry-point functions. - Specify Cell Array Inputs at the Command Line
Provide an example cell array, define a cell array type, or specify a cell array constant input. - Specify Global Cell Arrays at the Command Line
Specify global cell array inputs with the-globalsoption. - 在命令行中指定字符串标量输入
在命令行中指定字符串标量输入。
故障排除
- Resolve Issue: Using arguments Blocks to Specify Cell or Structure Entry-Point Input Types is Not Supported
Troubleshoot code generation error if cells or structs are used for input-type specification in the arguments block of an entry-point function.