Main Content
MATLAB Code Analysis
Identify and fix issues in MATLAB® code that prevent C/C++ code generation
Successful C/C++ code generation from MATLAB code depends on compliance with code generation rules and limitations. For example, your MATLAB code must only use MATLAB functions and toolbox functions supported for code generation. To identify and fix issues with your MATLAB code, prior to C/C++ code generation, you can use the Code Analyzer and Code Readiness Tool. To check that your MATLAB code produces generated code that works as expected, generate and execute a MEX function, which is executable and testable in the MATLAB environment.
Functions
coder.runTest | Run test replacing calls to MATLAB functions with calls to MEX functions |
coder.screener | Determine if function is suitable for code generation |
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 (Since R2022a) |
Properties
coder.CallSite Properties | Information about a function call site in your MATLAB code (Since 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 (Since R2022a) |
Topics
MATLAB Code Analysis Basics
- Identify Entry-Point Functions and Check MATLAB Code
Identify entry-point functions and check MATLAB code for errors before code generation. - 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. - Using MEX Functions That MATLAB Coder Generates
Accelerate your MATLAB function or test generated code for functionality and run-time issues. - Debug Generated C/C++ Code
Debug standalone C/C++ code generated from your MATLAB code.
Code Analyzer
- 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 Readiness Tool
- Code Generation Readiness Tool
The code generation readiness tool screens MATLAB code for features and functions that code generation does not support. - 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 Function Testing
- Workflow for Testing MEX Functions in MATLAB
Test MEX functions before generating C/C++ code. - Check for Issues in MATLAB Code Using MEX Functions
Use MEX functions to verify that the generated code provides the same functionality as the original MATLAB code. - Generate MEX Functions by Using the MATLAB Coder App
Follow the workflow for generating MEX functions with the MATLAB Coder™ app. - Generate MEX Functions at the Command Line
Follow the workflow for generating MEX functions withcodegen
. - 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 and Debugging 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.
Troubleshooting
- 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. - Resolve Error: Function Is Not Supported for Code Generation
Troubleshoot code generation failure of unsupported MATLAB functions.