Is there a way to get the name of a local function that runs in Matlab?

Is there a way to get the name of a local function that runs in Matlab?

Note: mfilename returns the name of the .m file, not the name of the local function.

+8
matlab
source share
2 answers

dbstack returns a structure with a full stack of function calls. To get information for a top-level function, use:

 S=dbstack fname=S(1).name 
+3
source share

There is a page on the Matlab Central website that seems to answer your question. Here is the code they recommend using:

 [ST,I] = dbstack; __PRETTY_FUNCTION__ = ST.name; 

__PRETTY_FUNCTION must contain the name of the local function to be executed.

+1
source share

All Articles