MATLAB Code Analysis

Prepare MATLAB® algorithm for code generation, fix errors, verify behavior using generated MEX function

Functions

codegen Generate C/C++ code from MATLAB code
coder.runTest Run test replacing calls to MATLAB functions with calls to MEX functions
coder.screener Determine if function is suitable for code generation

Examples and How To

Check Code with the Code Analyzer

Check for MATLAB code violations in the MATLAB Editor.

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.

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 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.

Fix Errors Detected at Code Generation Time

Fix errors and warnings listed in the code generation report.

Verify MEX Functions in the MATLAB Coder App

Compare results of running the original MATLAB function with the results from running the MEX function.

Collect and View Line Execution Counts for Your MATLAB Code

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

Verify MEX Functions at the Command Line

Test MEX functions with coder.runTest.

Debug Run-Time Errors

Debug issues with generated MEX functions.

Concepts

Workflow for Preparing MATLAB Code for Code Generation

Prepare MATLAB code for C/C++ code generation or code acceleration.

Design Considerations When Writing MATLAB Code for Code Generation

Consider design constraints when writing MATLAB code for code generation.

Fixing Errors Detected at Design Time

Fix errors detected by the code analyzer.

Using the Code Analyzer

Check for MATLAB code violations at design time.

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.

Workflow for Testing MEX Functions in MATLAB

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

Why Test MEX Functions in MATLAB?

Test a MEX function to verify that it provides the same functionality as the original MATLAB code.

Running MEX Functions

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

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.

Code Generation Reports

Generate and interpret code generation reports from MATLAB Coder.

Troubleshooting

Unable to Determine Code Generation Readiness

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

Slow Operations in MATLAB Coder App

Disable code generation readiness screening.

Was this topic helpful?