主要内容

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

MATLAB 类

R2026a
MATLAB® 类的代码生成

您可以为使用值类、句柄类和 System object 的 MATLAB 函数生成代码。要了解有关 MATLAB 中值和句柄类的更多信息,请参阅句柄类和值类的比较。要了解有关 System object 的更多信息,请参阅何谓 System object?。

在用于代码生成的 MATLAB 代码中,您可以:

  • 在 MATLAB 代码中使用 MATLAB 值或句柄类。

  • 使用 MATLAB 值类作为 MATLAB 入口函数的输入参量。

如果生成 C 代码,MATLAB 类表示为结构体。如果您生成 C++ 代码,代码生成器的默认行为是为 MATLAB 类生成 C++ 类。在用于代码生成的 MATLAB 代码中使用类时,您必须了解一些特定的用法说明和限制。

类

coder.ClassTypeRepresent set of MATLAB classes acceptable for input specification

对象

coder.ClassSignatureEntry-point class specification (Tech Preview) (自 R2026a 起)
coder.FunctionSignatureEntry-point function or method specification (Tech Preview) (自 R2026a 起)

函数

addMethodAdd method specification to coder.ClassSignature object (Tech Preview) (自 R2026a 起)

主题

代码生成基础知识

使用 MATLAB 类作为入口函数(技术预览)

在 MATLAB 函数中使用 MATLAB 类

将 MATLAB 类作为入口函数输入参量传递

疑难解答

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.

精选示例