MATLAB Function Reference | ![]() ![]() |
Set breakpoints in an M-file function
Graphical Interface
As an alternative to the dbstop
function, you can use the Breakpoints menu or the breakpoint alley in the Editor/Debugger.
Syntax
dbstop in mfile dbstop in mfile at lineno dbstop in mfile at subfun dbstop if error dbstop if all error dbstop if warning dbstop if naninf dbstop if infnan
Description
dbstop in mfile
temporarily stops execution of mfile
when you run it, at the first executable line, putting MATLAB in debug mode. mfile
must be in a directory that is on the search path or in the current directory. If you have graphical debugging enabled, the MATLAB Debugger opens with a breakpoint at the first executable line of mfile
. You can then use the debugging utilities, review the workspace, or issue any valid MATLAB function. Use dbcont
or dbstep
to resume execution of mfile
. Use dbquit
to exit from the Debugger.
dbstop in mfile at lineno
temporarily stops execution of mfile
when you run it, just prior to execution of the line whose number is lineno
, putting MATLAB in debug mode. mfile
must be in a directory that is on the search path or in the current directory. If you have graphical debugging enabled, the MATLAB Debugger opens mfile
with a breakpoint at line lineno
. If that line is not executable, execution stops and the breakpoint is set at the next executable line following lineno
. When execution stops, you can use the debugging utilities, review the workspace, or issue any valid MATLAB function. Use dbcont
or dbstep
to resume execution of mfile
. Use dbquit
to exit from the Debugger.
dbstop in mfile at subfun
temporarily stops execution of mfile
when you run it, just prior to execution of the subfunction subfun
, putting MATLAB in debug mode. mfile
must be in a directory that is on the search path or in the current directory. If you have graphical debugging enabled, the MATLAB Debugger opens mfile
with a breakpoint at the subfunction specified by subfun
. You can then use the debugging utilities, review the workspace, or issue any valid MATLAB function. Use dbcont
or dbstep
to resume execution of mfile
. Use dbquit
to exit from the Debugger.
dbstop if error
stops execution when any M-file you subsequently run produces a run-time error, putting MATLAB in debug mode, paused at the line that generated the error. The M-file must be in a directory that is on the search path or in the current directory. It does not include run-time errors that are detected within a try...catch
block. You cannot resume execution after an error. Use dbquit
to exit from the Debugger.
dbstop if all error
is the same as dbstop if error
, except that it stops execution on any type of run-time error, including errors that are detected within a try...catch
block.
dbstop if warning
stops execution when any M-file you subsequently run produces a run-time warning, putting MATLAB in debug mode, paused at the line that generated the warning. The M-file must be in a directory that is on the search path or in the current directory. Use dbcont
or dbstep
to resume execution.
dbstop if naninf
stops execution when any M-file you subsequently run encounters an infinite value (Inf
), putting MATLAB in debug mode, paused at the line where Inf
was encountered. The M-file must be in a directory that is on the search path or in the current directory. Use dbcont
or dbstep
to resume execution. Use dbquit
to exit from the Debugger.
dbstop if infnan
stops execution when any M-file you subsequently run encounters a value that is not a number (NaN
), putting MATLAB in debug mode, paused at the line where NaN
was encountered. The M-file must be in a directory that is on the search path or in the current directory. Use dbcont
or dbstep
to resume execution. Use dbquit
to exit from the Debugger.
Remarks
The at
, in
, and if
keywords, familiar to users of the UNIX debugger dbx, are optional.
Examples
The file buggy
, used in these examples, consists of three lines.
function z = buggy(x) n = length(x); z = (1:n)./x;
Example 1 - Stop at First Executable Line
dbstop in buggy buggy(2:5)
stop execution at the first executable line in buggy
n = length(x);
dbstep
advances to the next line, at which point, you can examine the value of n
.
Example 2 - Stop if Error
Because buggy
only works on vectors, it produces an error if the input x is a full matrix. The statements
dbstop if error buggy(magic(3))
??? Error using ==> ./ Matrix dimensions must agree. Error in ==> c:\buggy.m On line 3 ==> z = (1:n)./x; K»
Example 3 - Stop if Inf
In buggy
, if any of the elements of the input x
are zero, a division by zero occurs. The statements
dbstop if naninf buggy(0:2)
Warning: Divide by zero. > In c:\buggy.m at line 3 K»
See Also
dbclear
, dbcont
, dbdown
, dbquit
, dbstack
, dbstatus
, dbstep
, dbtype
, dbup
, partialpath
![]() | dbstep | dbtype | ![]() |