MATLAB Function Reference    

The name of the currently running M-file



mfilename returns a string containing the name of the most recently invoked M-file. When called from within an M-file, it returns the name of that M-file, allowing an M-file to determine its name, even if the filename has been changed.

p = mfilename('fullpath') returns the full path and name of the M-file in which the call occurs, not including the filename extension.

c = mfilename('class') in a method, returns the class of the method, not including the leading @ sign. If called from a non-method, it yields the empty string.


If mfilename is called with any argument other than the above two, it behaves as if it were called with no argument.

When called from the command line, mfilename returns an empty string.

To get the names of the callers of an M-file, use dbstack with an output argument.

See Also

dbstack, function, nargin, nargout, inputname

  mexext min