Here, where the solutions still stand:
However, I have another possible solution, which, in my opinion, is the βcleanestβ: using error handling mechanisms to get the stack trace. It depends on the version of MATLAB you are using ...
Versions of MATLAB 7.5 (R2007b) and later:
New error handling features in the form of the MException class were introduced in version 7.5 . You can get stack trace information from MException objects by throwing and throwing a "dummy" exception, and then immediately catching it and gaining access to the stack field. If you do the following in a function:
try throw(MException('phony:error','')); catch ME callerStack = {ME.stack.name}; end
Then the callerStack cell callerStack will contain the names of all the functions in the call stack, with the name of the current function in the first element and the uppermost caller name in the last element.
MATLAB 7.1 versions (R14SP3) - 7.4 (R2007a):
For these earlier versions, you can use the ERROR function to throw an error and LASTERROR to fix the error and get the stack information:
try error('phony:error',''); catch s = lasterror; callerStack = {s.stack.name}; end
Versions of MATLAB 7.0.4 (R14SP2) and earlier:
Unfortunately, the LASTERROR function has just begun to return stack trace information in MATLAB Version 7.1 , so there is no version of the above solutions that I can come up with for earlier versions of MATLAB.
source share