Main Content

Check MATLAB Function Using Code Analyzer

The Code Analyzer checks the MATLAB® function for code violations at design time, minimizing compilation errors. The Code Analyzer continuously checks your code as you enter it. It reports problems and recommends modifications.

To use the Code Analyzer to identify warnings and errors specific to MATLAB for deployment, you must add the %#codegen directive (or pragma) to your MATLAB function as described in Add Compilation Directive to MATLAB Function. A complete list of analyzer messages is available in the MATLAB Code Analyzer preferences. For more information, see Open the Code Analyzer Report.

To verify that continuous code checking is enabled:

  1. In MATLAB, select the Home tab and then click Preferences.

  2. In the Preferences dialog box, select Code Analyzer.

  3. In the MATLAB Code Analyzer Preferences pane, verify that Enable integrated warning and error messages is selected.

The analyzer provides an indicator in the top right of the editor window. If the indicator is green, the analyzer did not detect issues. For example, in the blinkLED function, the green color of the indicator specifies that the function has no errors or warnings.

If the indicator is red, the analyzer has detected errors in your code. If it is orange, then the analyzer has found a possible error in your code. When the indicator is red or orange, a red or orange marker appears to the right of the code where the error occurs. Place your pointer over the marker for information about the error. Click the underlined text in the error message for a more detailed explanation and suggested actions to fix the error.

Before deploying the MATLAB function on the hardware, you must fix the errors detected by the code Analyzer.

Related Topics