Main Content

Code Analyzer

Identify and address code issues

Since R2022b

Description

The Code Analyzer app generates a report of issues identified in code within a selected file or folder and its subfolders.

Using this app, you can:

  • Analyze code for issues, including problems and areas for improvement

  • View a summary of code issues

  • Filter and group issues by severity, issue type, and file

  • Link directly to the locations of code issues

Open the Code Analyzer App

  • MATLAB® Toolstrip: On the Apps tab, under MATLAB, click the app icon: Code Analyzer App Icon.

  • MATLAB command prompt: Enter codeAnalyzer.

Examples

expand all

Use the Code Analyzer app to analyze the code in a specified file or folder.

codeAnalyzer("C:\MyCode") 

This command launches the Code Analyzer app and generates a report of the issues found within the specified code. The summary section at the top of the report provides an overview of the information contained in the report. This section shows how many files were analyzed and the total number of errors, warnings, and informational messages found in the analyzed code.

Code Analyzer app showing an overall summary of code issues and code health details

Issues are grouped by severity by default. You can change how issues are grouped by using the Group By list. Group the report by file.

Code Analyzer report grouped by file.

You can filter the displayed messages by using the Filter by Severity and Filter by Issue Type lists. Filter the report to show only errors.

Code Analyzer report filtered by severity

Use the Code Analyzer app to fix issues in code.

Use the Code Analyzer app to analyze the code in a specified file or folder.

codeAnalyzer("C:\MyCode") 

Some issues have can be solved with automated replacement. These issues have Fix All button. If you expand the issue by clicking on it individual instances of the issues can be fixed clicking the corresponding Fix button. Hover the cursor over the Fix or Fix All buttons to see what fix MATLAB would implement. Note that some issues that can be fixed individually will not have a Fix All button available. These issues should be evaluated individually before applying automated fixes.

Code Analyzer report with fixable issues.

Related Examples

Programmatic Use

expand all

codeAnalyzer opens the Code Analyzer app. In the app, use the Select Folder button to choose the code to analyze.

codeAnalyzer(names) opens the Code Analyzer app and generates a report for files specified in names. If names is a folder path, then subfolders are included in the code analysis by default.

codeAnalyzer(names,IncludeSubfolders=false) restricts code analysis to the specified top level folder.

codeAnalyzer(codeIssue) opens the Code Analyzer app and generates a report based on the issues captured in the specified codeIssues object.

Version History

Introduced in R2022b