Main Content

Check theMATLABFunction Using Code Analyzer

TheCode Analyzerchecks 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%#codegendirective (or pragma) to your MATLAB function as described inAdd the Compilation Directive to the MATLAB Function. A complete list of analyzer messages is available in the MATLAB Code Analyzer preferences. For more information, seeRunning the Code Analyzer Report.

To verify that continuous code checking is enabled:

  1. In MATLAB, select theHometab and then clickPreferences.

  2. In the Preferences dialog box, selectCode Analyzer.

  3. In theMATLAB Code Analyzer Preferencespane, verify thatEnable integrated warning and error messages被选中。

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 theblinkLEDfunction, 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