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:
- 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, underMATLAB, click the app icon:
.
- MATLAB command prompt: Enter
codeAnalyzer
.
Examples
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.
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.
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.
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.
Related Examples
- Check Code for Errors and Warnings Using the Code Analyzer
- MATLAB Code Analyzer Report
- Configure Code Analyzer
Programmatic Use
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