Main Content

dbstep

Execute next executable line from current breakpoint

Description

dbstep executes the next executable line of the current file during debugging, skipping any breakpoints set in functions called by the current line.

example

dbstep in steps to the next executable line. If that line contains a call to another MATLAB® code file function, then execution steps to the first executable line of the called function. If no call exists to a MATLAB code file on that line, dbstep in is the same as dbstep.

example

dbstep out runs the rest of the current function and pauses just after leaving the function. MATLAB pauses execution at any breakpoint it encounters.

example

dbstep nlines executes the specified number of executable lines. MATLAB pauses execution at any breakpoint it encounters.

example

Examples

collapse all

Use dbstep to step over a called local function.

Create a file, myfile.m, that contains these statements.

function n = myfile(x)
n = myfunction(x-1);

function z = myfunction(y)
z = 2/y;

Set a breakpoint at the first line in myfile and run myfile with an input of 1. MATLAB pauses in the function myfile, at the line n = myfunction(x-1).

dbstop in myfile
myfile(2);
2   n = myfunction(x-1);

Step to the next execution line. MATLAB reaches the end of the function myfile.

K>> dbstep
End of function myfile.

Step once more to complete the execution of myfile and end debugging.

Use dbstep to step through a called local function.

Create a file, myfile.m, that contains these statements.

function n = myfile(x)
n = myfunction(x-1);

function z = myfunction(y)
z = 2/y;

Set a breakpoint at the first line in myfile and run myfile with an input of 2. MATLAB pauses in the function myfile, at the line n = myfunction(x-1).

dbstop in myfile
myfile(2);
2   n = myfunction(x-1);

Step into myfunction. MATLAB enters myfunction and pauses at the first line in the function.

K>> dbstep in
5   z = 2/y;

Step through the next four lines of code, completing the execution of myfile and ending debugging.

K>> dbstep 4
ans =

   2

Use dbstep to step into and out of a called local function.

Create a file, myfile.m, that contains these statements.

function n = myfile(x)
n = myfunction(x-1);

function z = myfunction(y)
z = 2/y;

Set a breakpoint at the first line in myfile and run myfile with an input of 2. MATLAB pauses in the function myfile, at the line n = myfunction(x-1).

dbstop in myfile
myfile(2);

Step into myfunction. MATLAB enters myfunction and pauses at the first line in the function.

K>> dbstep in
5   z = 2/y;

Step out of myfunction. MATLAB finishes executing myfunction and returns to the calling function myfile.

K>> dbstep out
2   n = myfunction(x-1);

Step out one more time to complete the execution of myfile and end debugging.

Input Arguments

collapse all

Number of executable lines to execute, specified as a positive integer.

Version History

Introduced before R2006a