Code Analyzer - Identify and address code issues - MATLAB (original) (raw)

Main Content

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:

Open the Code Analyzer App

Examples

expand all

Analyze Code

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

Fix Issues Within Code Analyzer

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 haveFix All button. If you expand the issue by clicking on it individual instances of the issues can be fixed clicking the correspondingFix button. Hover the cursor over theFix 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.

Programmatic Use

expand all

codeAnalyzer

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

codeAnalyzer(`names`)

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

codeAnalyzer(`names`,IncludeSubfolders=false)

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

codeAnalyzer(`codeIssue`)

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

Version History

Introduced in R2022b