Environmental Engineering Reference
In-Depth Information
arranged, it also is usually much more efficient, as special vectorized
implementations of the basic operations on a near-machine level are utilized.
2.7 Debugging of M-files
It was already said that the M-file, currently shown in the editor, is executed by
pressing the
button in the editor menu list. Alternative ways to do the same
thing are (1) pressing the F5 button, or (2) select the sub-menu entry 'Run' from the
'Debug' main entry. For the exploration of M-files some other debugging
commands are very convenient, which are explained here.
Debugging is a term, which came up with computer programming. Debugging is
the task to find and correct errors, so called bugs. If a program or an M-file does not
behave as intended, if there is still at least one erroneous statement, it is convenient
to stop the program execution at a certain point and watch the execution of the
following steps in detail. For such tasks several
tools are available in the
MATLAB
editor in the 'Debug' submenu.
A breakpoint , at which execution stops, can be set by the user easily by using the
column of '-'signs left from the line number counter in the editor window. A mouse
click initiates the bar to change into a red circle, indicating the location of a
breakpoint, as shown in Fig. 2.10 . When the program is run, execution stops at
the first breakpoint encountered. A green arrow indicates the current position of the
command execution (see Fig. 2.10 ).
Now the user may check the current values in variables. Moving the curser
through the editor window will make the contents of variables pop-up in small
boxes. Figure 2.11 depicts an example: variable T , which was touched by the cursor,
is a 1
®
1 double variable and currently contains the value 4. Another method for
checking variables at a breakpoint is more convenient, if the variable is a huge
array, and its contents can not be shown appropriately in a small box. The user can
change into the MATLAB
command window and examine the workspace, as
®
described in Chap. 1.
The button in the editor's main menu initiates the execution of the next line
only. Alternatives are the keyboard F10 button or the 'Step' entry in the 'Debug'
sub-menu. Now each command can be checked step by step, examining the effect
of the command on the variables involved. The green arrow on the left side of the
text window moves further with every step, always indicating the next command,
which is not jet executed. Although the 'Debug' commands and options were
designed for the programmer to find bugs in programs, these are also convenient
tools for novices to understand M-files, written by others. Novices are urged to try
the debug functionality on the loop of the M-file of the previous section.
There are further debugging tools,
for which the reader may view the
MATLAB
help. It is important to know that the
button (or key F5) always
®
Search WWH ::




Custom Search