fix
Syntax
Description
[
fixes the status
,results
] = fix(issues
,checkID
)checkID
issues found in issues
and
returns status
, a codeIssues
object
containing any remaining issues, and results
, a table that describes
the fix results.
[
fixes the issues in status
,results
] = fix(issues
,issuesTable
)issuesTable
.
Examples
Fix Issue in Code
Identify and fix issues in the file test.m
by
using the fix
object function for codeIssues
.
First, identify issues in the file test.m
by using codeIssues
.
issues = codeIssues("test.m")
issues = codeIssues with properties: Date: 18-Oct-2022 14:18:54 Release: "R2023a" Files: "C:\MyCode\test.m" CodeAnalyzerConfiguration: "active" Issues: [3×10 table] SuppressedIssues: [0×11 table] Issues table preview Location Severity Fixability Description CheckID LineStart LineEnd ColumnStart ColumnEnd FullFilename ________ ________ __________ ____________________________________________________________________________________________ _______ _________ _______ ___________ _________ __________________ "test.m" info manual "Variable appears to change size on every loop iteration. Consider preallocating for speed." AGROW 3 3 1 3 "C:\MyCode\test.m" "test.m" info auto "Add a semicolon after the statement to hide the output (in a script)." NOPTS 6 6 3 3 "C:\MyCode\test.m" "test.m" info auto "string('...') is not recommended. Use "..." instead." STRQUOT 8 8 1 13 "C:\MyCode\test.m"
Fix the STRQUOT
issue by using fix
.
[status,results] = fix(issues,"STRQUOT")
status = codeIssues with properties: Date: 18-Oct-2022 14:21:28 Release: "R2023a" Files: "C:\MyCode\test.m" CodeAnalyzerConfiguration: "active" Issues: [3×10 table] SuppressedIssues: [0×11 table] Issues table preview Location Severity Fixability Description CheckID LineStart LineEnd ColumnStart ColumnEnd FullFilename ________ ________ __________ ____________________________________________________________________________________________ _______ _________ _______ ___________ _________ __________________ "test.m" info manual "Variable appears to change size on every loop iteration. Consider preallocating for speed." AGROW 3 3 1 3 "C:\MyCode\test.m" "test.m" info auto "Add a semicolon after the statement to hide the output (in a script)." NOPTS 6 6 3 3 "C:\MyCode\test.m" results = 1×9 table Success ErrorMessage FullFilename CheckID LineStart LineEnd ColumnStart ColumnEnd ErrorID _______ ____________ __________________ _______ _________ _______ ___________ _________ _________ true <missing> "C:\MyCode\test.m" STRQUOT 8 8 1 13 <missing>
Fix Issue in Specific Files
Identify issues in the files test1.m
and
test2.m
and apply fixes to only one file using the
fix
object function for codeIssues
.
First, identify issues in the files test1.m
and
test2.m
by using codeIssues
.
issues = codeIssues(["test1.m" "test2.m"])
issues = codeIssues with properties: Date: 07-Dec-2022 10:52:15 Release: "R2023a" Files: [2×1 string] CodeAnalyzerConfiguration: "active" Issues: [5×10 table] SuppressedIssues: [0×11 table] Issues table preview Location Severity Fixability Description CheckID LineStart LineEnd ColumnStart ColumnEnd FullFilename _________ ________ __________ ____________________________________________________________________________________________ _______ _________ _______ ___________ _________ ___________________ "test1.m" info manual "Variable appears to change size on every loop iteration. Consider preallocating for speed." AGROW 3 3 1 3 "C:\MyCode\test1.m" "test1.m" info auto "Add a semicolon after the statement to hide the output (in a script)." NOPTS 6 6 3 3 "C:\MyCode\test1.m" "test1.m" info auto "string('...') is not recommended. Use "..." instead." STRQUOT 8 8 1 13 "C:\MyCode\test1.m" "test2.m" info auto "Add a semicolon after the statement to hide the output (in a script)." NOPTS 3 3 3 3 "C:\MyCode\test2.m" "test2.m" info auto "string('...') is not recommended. Use "..." instead." STRQUOT 5 5 1 13 "C:\MyCode\test2.m"
Fix the STRQUOT
issue by using fix
, but only
in the file test1.m
.
[status,results] = fix(issues,"STRQUOT","test1.m")
status = codeIssues with properties: Date: 07-Dec-2022 10:54:35 Release: "R2023a" Files: [2×1 string] CodeAnalyzerConfiguration: "active" Issues: [5×10 table] SuppressedIssues: [0×11 table] Issues table preview Location Severity Fixability Description CheckID LineStart LineEnd ColumnStart ColumnEnd FullFilename _________ ________ __________ ____________________________________________________________________________________________ _______ _________ _______ ___________ _________ ___________________ "test1.m" info manual "Variable appears to change size on every loop iteration. Consider preallocating for speed." AGROW 3 3 1 3 "C:\MyCode\test1.m" "test1.m" info auto "Add a semicolon after the statement to hide the output (in a script)." NOPTS 6 6 3 3 "C:\MyCode\test1.m" "test2.m" info auto "Add a semicolon after the statement to hide the output (in a script)." NOPTS 3 3 3 3 "C:\MyCode\test2.m" "test2.m" info auto "string('...') is not recommended. Use "..." instead." STRQUOT 5 5 1 13 "C:\MyCode\test2.m" results = 1×9 table Success ErrorMessage FullFilename CheckID LineStart LineEnd ColumnStart ColumnEnd ErrorID _______ ____________ ___________________ _______ _________ _______ ___________ _________ _________ true <missing> "C:\MyCode\test1.m" STRQUOT 8 8 1 13 <missing>
Fix Multiple Issues in Code
Identify and fix issues in the file test.m
by
using the fix
object function for codeIssues
.
First, identify issues in the file test.m
by using
codeIssues
.
issues = codeIssues("test.m")
issues = codeIssues with properties: Date: 18-Oct-2022 14:18:54 Release: "R2023a" Files: "C:\MyCode\test.m" CodeAnalyzerConfiguration: "active" Issues: [3×10 table] SuppressedIssues: [0×11 table] Issues table preview Location Severity Fixability Description CheckID LineStart LineEnd ColumnStart ColumnEnd FullFilename ________ ________ __________ ____________________________________________________________________________________________ _______ _________ _______ ___________ _________ __________________ "test.m" info manual "Variable appears to change size on every loop iteration. Consider preallocating for speed." AGROW 3 3 1 3 "C:\MyCode\test.m" "test.m" info auto "Add a semicolon after the statement to hide the output (in a script)." NOPTS 6 6 3 3 "C:\MyCode\test.m" "test.m" info auto "string('...') is not recommended. Use "..." instead." STRQUOT 8 8 1 13 "C:\MyCode\test.m"
Fix the issues found in test.m
. Use the table in the
Issues
property of issues
as the input for
fix
.
[status,results] = fix(issues,issues.Issues)
status = codeIssues with properties: Date: 07-Dec-2022 10:37:36 Release: "R2023a" Files: "C:\MyCode\test.m" CodeAnalyzerConfiguration: "active" Issues: [2×10 table] SuppressedIssues: [0×11 table] Issues table preview Location Severity Fixability Description CheckID LineStart LineEnd ColumnStart ColumnEnd FullFilename ________ ________ __________ ____________________________________________________________________________________________ _______ _________ _______ ___________ _________ __________________ "test.m" info manual "Variable appears to change size on every loop iteration. Consider preallocating for speed." AGROW 3 3 1 3 "C:\MyCode\test.m" results = 3×9 table Success ErrorMessage FullFilename CheckID LineStart LineEnd ColumnStart ColumnEnd ErrorID _______ ______________________________________________________________________ __________________ _______ _________ _______ ___________ _________ _____________________________________ false "The issue does not have an available fix in file 'C:\MyCode\test.m'." "C:\MyCode\test.m" AGROW 3 3 1 3 "MATLAB:codeanalyzer:CheckIDHasNoFix" true <missing> "C:\MyCode\test.m" NOPTS 6 6 3 3 <missing> true <missing> "C:\MyCode\test.m" STRQUOT 8 8 1 13 <missing>
Input Arguments
issues
— Code issues
codeIssues
object
Code issues, specified as a codeIssues
object.
checkID
— Issue check ID
character vector | string array | cell array of character vectors
Issue check identifier, specified as a character vector or string array. For a complete list of check identifiers, see Index of Code Analyzer Checks.
Example: "STRQUOT"
Example: ["STRQUOT" "AGROW"]
filenames
— Files to analyze
character vector | string array | cell array of character vectors
Files to fix, specified as a character vector, string array, cell array of character
vectors. A filename can include the full, relative, or partial path. The name of a file
must be a valid MATLAB® code or app file (.m
, .mlx
, or
.mlapp
).
Example: "../myFile.m"
Example: ["file1.mlx" "file2.mlapp"]
Example: "C:\MyCode\test.m"
issuesTable
— Table of issues
codeIssues.Issues
table
Table of issues, specified as a codeIssues.Issues
table.
Output Arguments
status
— Code status
codeIssues
object
Code status, returned as a codeIssues
object containing information on the status of the code after the function has applied
fixes.
results
— Fix results
table
Fix results, returned as a table with a row for each issue included in
checkID
or issuesTable
and with these
columns:
Column Name | Column Purpose |
---|---|
Success | Indicate if issue was fixed, returned as true or
false |
ErrorMessage | Describes why issue was not fixed; empty string if issue was fixed. |
FullFilename | Full path and filename of location of issue |
CheckID | Check identifier used to find this code issue |
LineStart | Line number where issue begins |
LineEnd | Line number where issue ends |
ColumnStart | Column number where issue begins |
ColumnEnd | Column number where issue ends |
ErrorID | Identifier for the error |
Version History
Introduced in R2023a
See Also
Objects
Apps
Functions
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)