Desktop Tools and Development Environment |
Set conditional breakpoints to cause MATLAB to stop at a specified line in a file only when the specified condition is met. One particularly good use for conditional breakpoints is when you want to examine results after a certain number of iterations in a loop. For example, set a breakpoint at line 10 in collatzplot
, specifying that MATLAB should stop only if N
is greater than or equal to 2
. This section covers the following topics:
Setting Conditional Breakpoints
To set a conditional breakpoint, follow these steps:
collatzplot
, enter
When you run the file, MATLAB enters debug mode and pauses at the line only when the condition is met. In the collatzplot
example, MATLAB runs through the for
loop once and pauses on the second iteration at line 10 when N
is 2
. If you continue executing, MATLAB pauses again at line 10 on the third iteration when N
is 3
.
Copying, Modifying, Disabling, and Clearing Conditional Breakpoints
To copy a conditional breakpoint, right-click the icon in the breakpoint alley and select Copy from the context menu. Then right-click in the breakpoint alley at the line where you want to paste the conditional breakpoint and select Paste from the context menu.
Modify the condition for the breakpoint in the current line by selecting Set/Modify Conditional Breakpoint from the Debug or context menu.
Click a conditional breakpoint icon to disable it. Click a disabled conditional breakpoint to clear it.
Function Alternative for Conditional Breakpoints
Use the dbstop
function with appropriate arguments to set conditional breakpoints from the Command Window, and use dbclear
to clear them. Use dbstatus
to view the breakpoints currently set, including any conditions, which are listed in the expression
field. If no condition exists, the value in the expression
field is [ ]
(empty). For details, see the function reference pages: dbstop
, dbclear
, and dbstatus
.
Running Sections in M-Files That Have Unsaved Changes | Breakpoints in Anonymous Functions |
© 1994-2005 The MathWorks, Inc.