Main Content



识别并修复 MATLAB® 代码中阻止生成 C/C++ 代码的问题

要从 MATLAB 代码成功生成 C/C++ 代码,需要遵循代码生成规则和限制。例如,您的 MATLAB 代码必须仅使用支持代码生成的 MATLAB 函数和工具箱函数。要在生成 C/C++ 代码之前识别和修复 MATLAB 代码的问题,您可以使用代码分析器和代码生成就绪工具进行检查。要检查您的 MATLAB 代码生成的代码是否符合预期,请生成并执行一个 MEX 函数,该函数可在 MATLAB 环境中执行和测试。


codegenMATLAB 代码生成 C/C++ 代码。
coder.runTestRun test replacing calls to MATLAB functions with calls to MEX functions
coder.screenerDetermine if function is suitable for code generation


MATLAB 代码分析基础知识

准备 MATLAB 代码以用于代码生成的工作流

准备 MATLAB 代码以用于 C/C++ 代码生成或代码加速。

Fixing Errors Detected at Design Time

Fix errors detected by the code analyzer.

Fix Errors Detected at Code Generation Time

Fix errors and warnings listed in the code generation report.

Debugging Strategies

Choose a strategy for detecting and correcting code that is not suitable for code generation.

Using MEX Functions That MATLAB Coder Generates

Accelerate your MATLAB function or test generated code for functionality and run-time issues.


Using the Code Analyzer

Check for MATLAB code violations at design time.

Check Code with the Code Analyzer

Check for MATLAB code violations in the MATLAB Editor.


Code Generation Readiness Tool

Interpret code generation readiness tool report.

Code Generation Readiness Screening in the MATLAB Coder App

The app screens your MATLAB code for unsupported features and functions.

Check Code by Using the Code Generation Readiness Tool

Run the code generation readiness tool at the command line, from the current folder browser, or in the app.

MEX 函数测试

Workflow for Testing MEX Functions in MATLAB

Test MEX functions before generating C/C++ code.

为什么要在 MATLAB 中测试 MEX 函数?

测试 MEX 函数,以确认它提供与原始 MATLAB 代码相同的功能。

使用 MATLAB Coder App 生成 MEX 函数

按照使用 MATLAB Coder™ App 生成 MEX 函数的工作流进行操作。

Generate MEX Functions at the Command Line

Follow the workflow for generating MEX functions with codegen.

Check for Run-Time Issues by Using the App

Detect and fix issues that are harder to find in generated standalone C/C++ code.

Running MEX Functions

Call a MEX function in the same way that you call the original MATLAB function.

Collect and View Line Execution Counts for Your MATLAB Code

See how well your test exercises MEX code generated from your MATLAB code.

Debug Run-Time Errors

Debug issues with generated MEX functions.


Unable to Determine Code Generation Readiness

The code generation readiness tool fails when it is unable to find your entry-point files.

Unable to Open a MATLAB Coder Project

Use a backup project file to revert to the format of an earlier release.

Slow Operations in MATLAB Coder App

Disable code generation readiness screening.