Function call stack
[ST,I] = dbstack(...)
dbstack displays the line numbers and file names of the function calls that led to the current breakpoint, listed in the order in which they were executed. The display lists the line number of the most recently executed function call (at which the current breakpoint occurred) first, followed by its calling function, which is followed by its calling function, and so on. This continues until the topmost MATLAB® function is reached. Each line number is a hyperlink you can click to go directly to that line in the Editor. The notation functionname>localfunctionname is used to describe the location of the local function.
Either none, one, or both n and '-completenames' can appear. If both appear, the order is irrelevant.
|file||The file in which the function appears. This field is the empty string if there is no file.|
|name||Function name within the file.|
|line||Function line number.|
The current workspace index is returned in I.
If you step past the end of a file, dbstack returns a negative line number value to identify that special case. For example, if the last line to be executed is line 15, then the dbstack line number is 15 before you execute that line and -15 afterwards.
This example shows the information returned when you issue dbstack while debugging a MATLAB code file:
dbstack In /usr/local/matlab/toolbox/matlab/cond.m at line 13 In test1.m at line 2 In test.m at line 3
This example shows the information returned when you issue dbstack while debugging lengthofline.m to get the complete name of the file, the function name, and line number in which the function appears:
[ST,I] = dbstack('-completenames') ST = file: 'I:\MATLABFiles\mymfiles\lengthofline.m' name: 'lengthofline' line: 28 I = 1
In addition to using dbstack while debugging, you can also use dbstack within a MATLAB code file outside the context of debugging. In this case, to get and analyze information about the current file stack. For example, to get the name of the calling file, use dbstack with an output argument within the file being called. For example: