Installation guide

6 Editing and Debugging M-Files
Finding Errors, Debugging, and Correcting M-Files
This section introduces general techniques for finding errors and using M-Lint
automatic code a naly zer to detect possible improvements in M-files. It then
illustrates MATLAB debugger features found in the Editor/Debugger, as well
equivalent Command Window debugging functions, using a simple example.
There are two kinds of errors:
Syntax errors For example, misspelling a function name or omitting a
parenthesis.
R u n-time errors These errors are usually algorithmic in nature. For
example,youmightmodifythewrongvariableorcodeacalculation
incorrectly. Run-time errors are usually apparent when an M-file produces
unexpected results. Run-time errors are difficult to track down because
the functio n’s local workspace is lost when the error forces a return to
the M ATLAB base workspace. The process of isolating and fixing these
run-time problems is referred to as debugging.
In addition to finding and fixing problems with your M-files, you might want to
improve the performance and make other enhancements using MATLAB tools.
Use the follow ing t echniques to isolate the causes of erro rs and improve your
M-files.
Technique or
To ol Description For More Information
Syntax
highlighting
and Delimiter
matching
Syntax highlighting helps you identify
unterminated strings in a n M-file before you run
the file.
Delimiter matching helps you correctly match
pairs of parentheses, brackets, braces, and
keywords.
“Syntax Highlighting” on
page 6-28
“Matching Delimiters
(Parentheses)” on page
3-17
6-84