MATLAB: Does the MFILENAME function fail to work with EVALIN in MATLAB 7.0.4 (R14SP2)

basecallerdbstackevalinMATLABmfilename

I have created two functions "myfun1" and "myfun2". The "myfun1" function calls the "myfun2" function. In "myfun2", I have the following code:
function myfun2
mfilename
evalin('caller', 'mfilename')
and here is myfun1 function:
function myfun1
myfun2
When I execute the function by typing in the following command:
myfun1
I receive the following output:
ans =
myfun2
ans =
myfun2
I expect the output to be:
ans =
myfun2
ans =
myfun1

Best Answer

This is expected behavior in MATLAB. The MFILENAME function returns a string containing the name of the most recently invoked MATLAB script or function, which is the same regardless of the workspace. Calling MFILENAME in different workspaces does not affect the output of the function.
To obtain the name of the function that calls the current function, use the DBSTACK function.
For information about the DBSTACK function, refer to the documentation by typing the following command in MATLAB:
doc dbstack