| Development Environment | ![]() |
Stepping Through an M-File
While in debug mode, you can step through an M-file, pausing at points where you want 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 Equivalent |
| Continue |
Continue execution of M-file until completion or until another breakpoint is encountered. The menu item says Run or Save and Run if the file is not running. |
|
|
| 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. |
|
|
| Step In |
Execute the current line of the M-file and, if the line is a call to another function, step into that function. |
|
|
| Step Out |
After stepping in, runs the rest of the called function or subfunction, leaves the called function, and pauses. |
|
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 in takes you to line 9 of collatz.
The pause indicator at line 10 of collatzplot changes to a hollow arrow
, indicating that MATLAB control is now in a function called from the main program, which in the example is 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. The fastest 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 | Examining Values | ![]() |