Main Content

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

生成代码

生成代码和编译独立的库及可执行文件

C/C++ 代码生成是 MATLAB® Coder™ 的核心功能。您可以使用 coder 函数打开 App 以生成代码,也可以使用 codegen 函数从命令行生成代码。App 提供了贯穿代码生成过程的分步指导,包括最佳做法指导,还有关于代码生成设置和选项的清晰的可视化帮助。命令行工作流则让您能够以简单、可重复且高效的方式启动代码生成。代码生成工作流支持许多不同数据类型,包括可变大小数据和全局数据。该工作流还支持多个入口(顶层)函数、多签名 MEX 函数生成以及基本属性的自定义,例如生成代码的数组布局和数组索引。此外,您可以生成使用关键 C++ 语言功能(如类、命名空间和函数重载)的代码。

App

全部展开

MATLAB CoderMATLAB 代码生成 C 代码或 MEX 函数

函数

全部展开

coder打开 MATLAB Coder
codegenMATLAB 代码生成 C/C++ 代码。
coder.target确定代码生成目标是否为指定的目标
coder.allowpcode从 P 代码文件控制代码生成
coder.config创建 MATLAB Coder 代码生成配置对象
coder.extrinsic将函数声明为外部函数,并在 MATLAB 中执行它
coder.load从 MAT 文件或 ASCII 文件加载编译时常量
coder.nullcopy在代码生成中声明未初始化的变量
coder.newtypeCreate coder.Type object to represent type of an entry-point function input
coder.varsize声明可变大小数据
coder.typeofCreate coder.Type object to represent the type of an entry-point function input
coder.resize调整 coder.Type 对象的大小
coder.ceval调用外部 C/C++ 函数
coder.cinclude在生成的代码中包括头文件
coder.cstructname在生成代码中命名 C 结构体类型
coder.opaque在生成的代码中声明变量
coder.ref指示要传引用的数据
coder.rref指示要传引用的只读数据
coder.wref指示要按引用传递的只写数据

对象

全部展开

coder.MexCodeConfigConfiguration parameters for MEX function generation from MATLAB code
coder.CodeConfigConfiguration parameters for C/C++ code generation from MATLAB code
coder.EmbeddedCodeConfigConfiguration parameters for C/C++ code generation from MATLAB code with Embedded Coder
coder.OutputTypeOutput type from an entry-point function to specify as an input type

主题

生成代码基础知识

在命令行和工程工作流之间切换

特定于数据的工作流

扩展功能

扩展的 C++ 功能

代码外观

  • Reserved Keywords
    Certain words in your code, that are C/C++ keywords, might be renamed in the generated code.