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.
Fixing issues in live scripts (.mlx
) and apps
(.mlapp
) is not supported.
[
fixes the issues in status
,results
] = fix(issues
,issuesTable
)issuesTable
.
Examples
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>
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>
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
Code issues, specified as a codeIssues
object.
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"]
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 .m
file. .mlx
and
.mlapp
files in filenames
are ignored.
Example: "../myFile.m"
Example: ["file1.m" "file2.m"]
Example: "C:\MyCode\test.m"
Table of issues, specified as a codeIssues.Issues
table.
Output Arguments
Code status, returned as a codeIssues
object containing information on the status of the code after the function has applied
fixes.
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.
Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.
América
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- 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)