MATLAB Function Reference
  Go to function:
    Search    Help Desk 
dbstop    Examples   See Also

Set breakpoints in an M-file function

Syntax

Description

The 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 if error
Stops execution if a runtime error occurs in any M-file function. You can examine the local workspace and sequence of function calls leading to the error, but you cannot resume M-file execution after a runtime error.
dbstop if naninf
Stops execution when it detects Not-a-Number (NaN) or Infinity (Inf).
dbstop if infnan
Stops execution when it detects Not-a-Number (NaN) or Infinity (Inf).
dbstop if warning
Stops execution if a runtime warning occurs in any M-file function.

Regardless of the form of the 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.

Examples

Here is a short example, printed with the dbtype command to produce line numbers.

The statement

causes execution to stop at line 2, the first executable line. The command

then 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

produce

Finally, if any of the elements of the input x are zero, a division by zero occurs. For example, consider

which produces

See Also

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.



[ Previous | Help Desk | Next ]