The Code Analyzer Report displays potential errors and problems,
as well as opportunities for improvement in your code through messages.
For example, a common message indicates that a variable
Note: MATLAB® does not support creating Code Analyzer reports for live scripts. When creating a report for all files in a folder, all live scripts in the selected folder are excluded from the report.
To run the Code Analyzer Report:
In the Current Folder browser, navigate
to the folder that contains the files you want to check. To use the
example shown in this documentation,
you can change the current folder by running
If you plan to modify the example, save the file to a
folder for which you have write access. Then, make that folder the
current MATLAB folder. This example saves the file in
In the Current Folder browser, click , and then select Reports > Code Analyzer Report.
The report displays in the MATLAB Web Browser, showing those files identified as having potential problems or opportunities for improvement.
For each message in the report, review the suggestion and your code. Click the line number to open the file in the Editor at that line, and change the file based on the message. Use the following general advice:
If you are unsure what a message means or what to change in the code, click the link in the message if one appears. For details, see Check Code for Errors and Warnings.
If the message does not contain a link, and you are
unsure what a message means or what to do, search for related topics
in the Help browser. For examples of messages and what to do about
them, including specific changes to make for the example,
see Changing Code Based on Code Analyzer Messages.
The messages do not provide perfect information about every situation and in some cases, you might not want to change anything based on the message. For details, see Understand the Limitations of Code Analysis.
If there are certain messages or types of messages you do not want to see, you can suppress them. For details, see Adjust Code Analyzer Message Indicators and Messages.
After modifying it, save the file. Consider saving the file to a different name if you made significant changes that might introduce errors. Then you can refer to the original file, if needed, to resolve problems with the updated file. Use the Compare button on the Editor or Live Editor tab to help you identify the changes you made to the file. For more information, see Comparing Text Files.
Run and debug the file or files again to be sure that you have not introduced any inadvertent errors.
If the report is displaying, click Rerun This Report to update the report based on the changes you made to the file. Ensure that the messages are gone, based on the changes you made to the files.
For information on how to correct the potential problems presented in Code Analyzer messages, use the following resources:
Open the file in the Editor and click the Details button in the tooltip, as shown in the image following this list. An extended message opens. However, not all messages have extended messages.
Use the Help browser Search pane to find documentation about terms presented in the messages.
The following image shows a tooltip with a Details button.
The orange line under the equals (
sign indicates a tooltip displays if you hover over the equals sign.
The orange highlighting indicates that an automatic
fix is available.
You can get Code Analyzer messages using any of the following methods. Each provides the same messages, but in a different format:
Access the Code Analyzer Report for a file from the Profiler detail report.
which analyzes the specified file and displays messages in the Command
checkcode and displays the messages
in the Web Browser.
Use automatic code checking while you work on a file in the Editor. See Automatically Check Code in the Editor — Code Analyzer. Automatic code checking is not supported in live scripts.