MATLAB 代码分析
识别并修复 MATLAB® 代码中阻止生成 C/C++ 代码的问题
要从 MATLAB 代码成功生成 C/C++ 代码,需要遵循代码生成规则和限制。例如,您的 MATLAB 代码必须仅使用支持代码生成的 MATLAB 函数和工具箱函数。要在生成 C/C++ 代码之前识别和修复 MATLAB 代码的问题,您可以使用代码分析器和代码生成就绪工具进行检查。要检查您的 MATLAB 代码生成的代码是否符合预期,请生成并执行一个 MEX 函数,该函数可在 MATLAB 环境中执行和测试。
函数
coder.runTest | Run test replacing calls to MATLAB functions with calls to MEX functions |
coder.screener | 确定函数是否适合代码生成 |
getLineColumn | Find locations of beginning and end of MATLAB code involved in code generation |
textReport | Export code generation readiness report to base workspace as a character vector (自 R2022a 起) |
属性
coder.CallSite Properties | Information about a function call site in your MATLAB code (自 R2022a 起) |
coder.CodeFile Properties | Description of file containing text that is involved in code generation |
coder.File Properties | Description of file without text that is involved in code generation |
coder.Message Properties | Description of message produced during code generation readiness analysis or during code generation |
coder.ScreenerInfo Properties | Code generation readiness information (自 R2022a 起) |
主题
MATLAB 代码分析基础知识
- 准备 MATLAB 代码以用于代码生成的工作流
准备 MATLAB 代码以用于 C/C++ 代码生成或代码加速。 - Fixing Errors Detected at Design Time
Fix errors detected by the code analyzer. - 修复在代码生成时检测到的错误
修复在代码生成报告中列出的错误和警告。 - Debugging Strategies
Choose a strategy for detecting and correcting code that is not suitable for code generation. - 使用 MATLAB Coder 生成的 MEX 函数
提高您的 MATLAB 函数的执行速度或测试生成的代码是否存在功能和运行时问题。 - Debug Generated C/C++ Code
Debug standalone C/C++ code generated from your MATLAB code.
代码分析器
- 使用代码分析器
在设计时检查 MATLAB 代码冲突。 - Check Code with the Code Analyzer
Check for MATLAB code violations in the MATLAB Editor.
代码就绪工具
- 代码生成就绪工具
代码生成就绪工具会筛查 MATLAB 代码中是否存在代码生成不支持的功能和函数。 - 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 函数测试
- 在 MATLAB 中测试 MEX 函数的工作流
在生成 C/C++ 代码之前测试 MEX 函数。 - 为什么要在 MATLAB 中测试 MEX 函数?
测试 MEX 函数,以确认它提供与原始 MATLAB 代码相同的功能。 - 使用 MATLAB Coder 生成 MEX 函数
按照使用 MATLAB Coder™ 生成 MEX 函数的工作流进行操作。 - 在命令行中生成 MEX 函数
按照使用codegen
生成 MEX 函数的工作流进行操作。 - 使用 App 检查运行时问题
检测并修复在生成的独立 C/C++ 代码中难以发现的问题。 - 运行和调试 MEX 函数
调用 MEX 函数的方式与调用原始 MATLAB 函数的方式相同。 - 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. - 无法打开 MATLAB Coder 工程
使用备份工程文件还原到以前的版本的格式。 - Slow Operations in MATLAB Coder App
Disable code generation readiness screening. - 解决错误:代码生成不支持函数
对不支持的 MATLAB 函数的代码生成失败进行故障排除。