MATLAB Function Reference | Search  Help Desk |
dbstop | Examples See Also |
Set breakpoints in an M-file function
dbstop atlineno
infunction
dbstop infunction
dbstop if
|
where |
|
error
|
dbstop
command sets up MATLAB's debugging mode. dbstop
sets a breakpoint at a specified location in an M-file function or causes a break in case an error or warning occurs during execution. When the specified dbstop
condition is met, the MATLAB prompt is displayed and you can issue any valid MATLAB command.
dbstop at lineno
in function
stops execution just prior to execution of that line of the specified M-file function. function
must be the name of an M-file function or a MATLABPATH
relative partial pathname.
dbstop in function
stops execution before the first executable line in the M-file function when it is called.
dbstop if keyword
stops execution under the specified conditions:dbstop
command, when a stop occurs, the line or error condition that caused the stop is displayed. To resume M-file function execution, issue a dbcont
command or step to another line in the file with the dbstep
command.
Any breakpoints set by the first two forms of the dbstop
command are cleared if the M-file function is edited or cleared.
The at
, in
, and if
keywords, familiar to users of the UNIX debugger dbx, are optional.
Here is a short example, printed with the dbtype
command to produce line numbers.
dbtype buggy 1 function z = buggy(x) 2 n = length(x); 3 z = (1:n)./x;The statement
dbstop in buggycauses execution to stop at line 2, the first executable line. The command
dbstepthen advances to line 3 and allows the value of
n
to be examined.
The example function only works on vectors; it produces an error if the input x
is a full matrix. So the statements
dbstop if error buggy(magic(3))produce
Error using ==>./ Matrix dimensions must agree. Error in ==> buggy.m On line 3 ==> z = (1:n)./x;Finally, if any of the elements of the input
x
are zero, a division by zero occurs. For example, consider
dbstop if naninf buggy(0:2)which produces
Warning: Divide by zero NaN/Inf debugging breakpoint hit on line 2. Stopping at next line. 2 n = length(x); 3 z = (1:n)./x;
dbclear
Clear breakpoints
dbcont
Resume execution
dbdown
Change local workspace context (down)
dbquit
Quit debug mode
dbstack
Display function call stack
dbstatus
List all breakpoints
dbstep
Execute one or more lines from a breakpoint
dbtype
List M-file with line numbers
dbup
Change local workspace context (up)
See also partialpath.