Development Environment    

Stepping Through an M-File

While in debug mode, 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 use the equivalent functions.

Toolbar Button
Debug Menu Item
Description
Function Alternative

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
Execute the current line of the M-file.
dbstep

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
After stepping in, run the rest of the called function or subfunction, leave the called function, and pause.
dbstep out

Stepping In.   In the example, collatzplot is paused at line 10. 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 takes you to line 9 of collatz. If collatz is not open in the Editor, it automatically opens if you have selected the Editor/Debugger preference to Automatically open files while 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, you can do the same things you can do in the main (calling) function--set breakpoints, run, step through, and examine values.

Stepping Out.   In the example, the program is paused at step 9 in collatz. Because the problem results are correct for n = 1, continue running the program since there is no need to examine values until n = 2. One way to run through collatz is to step out, which runs the rest of collatz and returns to the next line in collatzplot, line 11. To step out, use the step-out button or type dbstep out in the Command Window.


  Running an M-File with Breakpoints Examining Values