How do I get a list of currently executing functions?

3 ビュー (過去 30 日間)
Harry Dymond
Harry Dymond 2020 年 12 月 14 日
コメント済み: Harry Dymond 2020 年 12 月 14 日
Before you say it, dbstack does not solve my problem!
dbstack is really a list of executing code files, as opposed to a list of executing functions. My specific problem arises as I have created a class that has a custom loadobj function. loadobj can be called as a result of using the "load" function, or uiopen and then selecting a .mat file, or drag & drop of .mat file into the base workspace, and probably a few other ways too. However, it can also be called as a result of calling the "whos" function. Now, I need by custom loadobj function to be able to distinguish if has been called as a result of "load" or "whos" and act differently in each case.
Here's a super-simple example to recreate the problem:
Define class with custom loadobj:
classdef Load_Test
methods (Static, Hidden)
function objOut = loadobj(objIn)
fprintf(2, '\ncustom load function called!\n\n');
objOut = objIn;
create instance of object:
bob = Load_Test;
save to workspace:
The custom loadobj function of the Load_Test class executes, as expected.
whos('-file', 'bob.mat')
The custom loadobj function executes in this case also.
So, how can I determine, inside of the loadobj function, why it has been called? If the "load" and "whos" functions are called from the MATLAB command line, then the only thing that is in the call stack is the Load_Test class file itself.
Thanks for reading and any help gratefully received.
  2 件のコメント
Harry Dymond
Harry Dymond 2020 年 12 月 14 日
My class implements a custom figure-creation tool. I want loadobj to recreate the figure associated with the object only in the load case, and not draw the figure in the whos case.


回答 (0 件)


Find more on Startup and Shutdown in Help Center and File Exchange




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by