Stack call in compiled matlab

In MATLAB, you can use dbstack to get the call stack at the current time, however dbstack is not available in the stand-alone compiled version of MatLab programs, is there an alternative to get the call stack, or at least the current call function function? I want to write an object function that needs to know who it was called by, but a full call stack would be preferable.

+4
source share
1 answer

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.

+11
source

All Articles