MATLAB 类
您可以为使用值类、句柄类和 System object 的 MATLAB 函数生成代码。要了解有关 MATLAB 中值和句柄类的更多信息,请参阅句柄类和值类的比较。要了解有关 System object 的更多信息,请参阅何谓 System object?。
在用于代码生成的 MATLAB 代码中,您可以:
在 MATLAB 代码中使用 MATLAB 值或句柄类。
使用 MATLAB 值类作为 MATLAB 入口函数的输入参量。
如果生成 C 代码,MATLAB 类表示为结构体。如果您生成 C++ 代码,代码生成器的默认行为是为 MATLAB 类生成 C++ 类。在用于代码生成的 MATLAB 代码中使用类时,您必须了解一些特定的用法说明和限制。
类
coder.ClassType | Represent set of MATLAB classes acceptable for input specification |
对象
coder.ClassSignature | Entry-point class for code generation (Tech Preview) (自 R2026a 起) |
coder.FunctionSignature | Entry-point function or method for code generation (Tech Preview) (自 R2026a 起) |
函数
addMethod | Add method specification to coder.ClassSignature object (Tech
Preview) (自 R2026a 起) |
主题
代码生成基础知识
- 用于代码生成的 MATLAB 类定义
在用于进行代码生成的 MATLAB 代码中使用类。 - 为代码生成定义类属性
- MATLAB 代码生成中的 System object
在 MATLAB 生成的代码中使用 System object 的特殊注意事项。 - 句柄类析构函数的代码生成
在用于进行代码生成的 MATLAB 代码中使用句柄类析构函数。 - Generate C++ Code for MATLAB Classes
Generate a C++ class for a value class, handle class, or System object™ in your MATLAB code. - Generate Class Interface in C++ Code
Generate C++ code that is packaged into a class.
使用 MATLAB 类作为入口函数(技术预览)
- Generate Standalone Code for Entry-Point Class (Tech Preview)
Use a MATLAB class as an entry-point for code generation. (自 R2026a 起) - Generate C++ Executable for Entry-Point System Object in a Namespace (Tech Preview)
Use a System object in a namespace as an entry point for code generation. (自 R2026a 起) - Generate and Use C++ Classes from Entry-Point Classes That Model a Physical System (Tech Preview)
Use generated entry-point C++ classes in a main function. (自 R2026a 起)
在 MATLAB 函数中使用 MATLAB 类
- 为 MATLAB 值类生成代码
在用于代码生成的 MATLAB 代码中使用值类。 - Generate Code for MATLAB Functions That Use Handle Classes
Use a handle class in MATLAB code intended for code generation. - Generate Code for MATLAB Functions That Use System Objects
Use a System object in MATLAB code for code generation. - Generate Code for MATLAB Functions That Use Singleton Classes
Use a singleton handle class in MATLAB code for code generation.
将 MATLAB 类作为入口函数输入参量传递
- Specify Value Class Objects as Inputs
Specify that an entry-point input is an object of a value class.
疑难解答
Resolve Error: Handle Object Referenced by Persistent Variable
Troubleshoot error when using a persistent handle object.
Resolve Error: Nontunable Property Cannot Be Defined by Subscripted Assignment
Troubleshoot code generation failure when a System object uses a structure.
Resolve Error: Class Properties Must Be Fully Defined Before Use
Troubleshoot code generation error when class properties are not defined before use.
Resolve Error: Cannot Reference Handle Object Outside of Loop
Troubleshoot error when creating or allocating a handle object inside a
for-loop.
句柄类的属性赋值问题故障排除。
某些属性无法与 coder.ref、coder.rref 或 coder.wref 结合使用。
Resolve Error: Code Generator Failed to Produce C++ Destructor for MATLAB Class
Troubleshoot generation of standalone code for C++ destructor of a MATLAB class.
对 MATLAB 代码中对象数组的代码生成失败进行故障排除。
Resolve Error: coder.varsize Not Supported for Class Properties
Troubleshoot code generation error when using coder.varsize
with properties of a MATLAB class.
