函数定义
模块
MATLAB Function | 将 MATLAB 代码包含在生成可嵌入式 C 代码的模型中 |
MATLAB System | 在模型中包含 System object |
函数
coder.extrinsic | 将函数声明为外部函数,并在 MATLAB 中执行它 |
coder.ignoreSize | Prevent code generator from creating function specializations for constant-size expressions |
coder.ignoreConst | Prevent use of constant value of expression for function specializations |
coder.unroll | 通过为每次循环迭代生成循环体的副本来展开 for 循环 |
coder.sameSizeBinaryOp | Apply element-wise binary operations without implicit expansion |
coder.noImplicitExpansionInFunction | Disable implicit expansion within the specified function in the generated code |
主题
- 编译指令 %#codegen
指示 MATLAB® 函数用于代码生成。
- Generate Code With Implicit Expansion Enabled
The code generator introduces modifications in the generated code to accomplish implicit expansion.
- Optimize Implicit Expansion in Generated Code
Implicit expansion in the generated code is enabled by default.
- Code Generation for Variable Length Argument Lists
Generate code for
varargin
andvarargout
. - Generate Code for arguments Block That Validates Input and Output Arguments
Generate code for MATLAB code that constrains class, size, and other aspects of function input and output values.
- 递归函数的代码生成
在用于代码生成的 MATLAB 代码中使用递归函数。
- Force Code Generator to Use Run-Time Recursion
Rewrite your MATLAB code so that the code generator uses run-time recursion instead of compile-time recursion.
- 匿名函数的代码生成
在用于代码生成的 MATLAB 代码中使用匿名函数。
- Code Generation for Nested Functions
Use nested functions in MATLAB code intended for code generation.
- 代码生成的函数调用解析
代码生成器使用优先级规则来解析函数调用。
- 代码生成路径中文件类型的解析
代码生成器使用优先级规则来解析文件类型。
- 使用 MATLAB 引擎在生成的代码中执行函数调用
如果代码生成不支持某个函数,请将其声明为外部函数以在 MATLAB 中执行。
疑难解答
Nonconstant Index into varargin or varargout in a for-Loop
Force loop unrolling when the code generator cannot
determine the value of the index into varargin
or varargout
.
Avoid Duplicate Functions in Generated Code
Reduce the occurrence of duplicate functions in the generated code.
Output Variable Must Be Assigned Before Run-Time Recursive Call
Troubleshoot output variable assignment for run-time recursion.
Compile-Time Recursion Limit Reached
Troubleshoot compile-time recursion limit error.
Resolve Error: Size Mismatches
Troubleshoot size mismatch errors that occur during code generation.