Desktop Tools and Development Environment Previous page   Next Page

Setting Standard Breakpoints

To set a standard breakpoint using the Editor/Debugger, click in the breakpoint alley at the line where you want to set the breakpoint. The breakpoint alley is the narrow column on the left side of the Editor/Debugger, just right of the line number. Set breakpoints at lines that are preceded by a - (dash). Lines not preceded by a dash, such as comments or blank lines, are not executable--if you try to set a breakpoint there, it is actually set at the next executable line. Other ways to set a breakpoint are to position the cursor in the line and then click the Set/Clear Breakpoint button on the toolbar, or select Set/Clear Breakpoint from the Debug menu or the context menu. A breakpoint icon appears.

Set Breakpoints for the Example.   It is unclear whether the problem in the example is in collatzplot or collatz. To start, set breakpoints in collatzplot.m at lines 10, 11, and 12. The breakpoint at line 10 allows you to step into collatz to see if the problem might be there. The breakpoints at lines 11 and 12 stop the program where you can examine the interim results.

Image of collatzplot.m in Editor/Debugger showing breakpoints at lines 10, 11, and 12. Click a dash in the breakpoint alley to set a breakpoint at that line.

Valid (Red) and Invalid (Gray) Breakpoints.   Red breakpoints are valid standard breakpoints. If breakpoints are instead gray, they are not valid.

Image of invalid breakpoints (gray) in Editor/Debugger. In this example, the breakpoints are invalid because changes to the file have not been saved. When you save the file, the breakpoints become valid and turn from gray to red.

Breakpoints are gray for either of these reasons:

Function Alternative for Setting Breakpoints

To set a breakpoint using the debugging functions, use dbstop. For the example, type

dbstop in collatzplot at 10
dbstop in collatzplot at 11
dbstop in collatzplot at 12

Some useful related functions are


Previous page  Setting Breakpoints Running an M-File with Breakpoints Next page

© 1994-2005 The MathWorks, Inc.