Desktop Tools and Development Environment Previous page   Next Page

Stepping Through an M-File

While debugging, you can step through an M-file, pausing at points where you want to examine values.

Use the step buttons or the step items in the Debug menu of the Editor/Debugger or desktop, or use the equivalent functions.

Toolbar Button
Debug Menu Item
Description
Function Alternative

Continue or Run or Save and Run button

Continue or Run or
Save and Run
Continue execution of M-file until completion or until another breakpoint is encountered. The menu item says Run or Save and Run if a file is not already running.
dbcont
None
Go Until Cursor
Continue execution of M-file until the line where the cursor is positioned. Also available on the context menu.
None

Step button

Step
Execute the current line of the M-file.
dbstep

Step in button

Step In
Execute the current line of the M-file and, if the line is a call to another function, step into that function.
dbstep in

Step out button

Step Out
After stepping in, run the rest of the called function or subfunction, leave the called function, and pause.
dbstep out

Continue Running in the Example

In the example, collatzplot is paused at line 10. Because the problem results are correct for N/n = 1, we want to continue running until N/n = 2. Press the Continue button three times to move through the breakpoints at lines 10, 11, and 12. Now the program is again paused at the breakpoint at line 10.

Stepping In to Called Function in the Example

Now that collatzplot is paused at line 10 during the second iteration, use the Step In button or type dbstep in in the Command Window to step into collatz and walk through that M-file. Stepping into line 10 of collatzplot goes to line 9 of collatz. If collatz is not open in the Editor/Debugger, it automatically opens if you have selected Debug -> Open M-Files When Debugging.

The pause indicator at line 10 of collatzplot changes to a hollow arrow , indicating that MATLAB control is now in a subfunction called from the main program. The call stack shows that the current function is now collatz.

In the called function, collatz in the example, you can do the same things you can do in the main (calling) function--set breakpoints, run, step through, and examine values.


Previous page  Running an M-File with Breakpoints Examining Values Next page

© 1994-2005 The MathWorks, Inc.