How do I get a list of currently executing functions?
10 views (last 30 days)
Show older comments
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;
end
end
end
create instance of object:
bob = Load_Test;
save to workspace:
save('bob.mat')
Now:
load('bob.mat')
The custom loadobj function of the Load_Test class executes, as expected.
Run:
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 Comments
Steven Lord
on 14 Dec 2020
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.
Why? In both cases you need to take the bytes on disk and turn them into an object so you can ask questions of that object (in particular, "What is your size?" especially if the class has an overloaded size method.)
What do you want to do in the load case but not in the whos case or vice versa?
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!