Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get the name of the local function that is being run in Matlab?

Tags:

matlab

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.

like image 319
Argyll Avatar asked Jul 10 '15 05:07

Argyll


People also ask

How do I find the path of a function in MATLAB?

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 .

What is a subfunction in MATLAB?

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.

How do you name a function in MATLAB?

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.

What is the name of a primary function in MATLAB?

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.


1 Answers

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
like image 56
Daniel Avatar answered Oct 19 '22 04:10

Daniel