Is there a way to get the name of the local function that is being run in Matlab?
Note: mfilename
returns the name of the .m file, not the name of the local function.
You can use -all with the input arguments of any of the previous syntaxes. str = which( item ) returns the full path for item to str . str = which( fun1 ,'in', fun2 ) returns the path to function fun1 that is called by file fun2 .
Additional functions within the file are called local functions, and they can occur in any order after the main function. Local functions are only visible to other functions in the same file. They are equivalent to subroutines in other programming languages, and are sometimes called subfunctions.
Valid function names begin with an alphabetic character, and can contain letters, numbers, or underscores. You can save your function: In a function file which contains only function definitions. The name of the file must match the name of the first function in the file.
The program description is mainly a self-contained set of statements which comprises of lines of codes or different kinds of functions. Thus the name of the primary function, where the program description is described, is the M-file.
dbstack
returns a struct with the full function call stack. To get the information for the top level function, use:
S=dbstack
fname=S(1).name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With