Clear Filters
Clear Filters

How do I get a list of currently executing functions?

14 views (last 30 days)
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
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?
Harry Dymond
Harry Dymond on 14 Dec 2020
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.

Sign in to comment.

Answers (0)

Categories

Find more on Object Save and Load in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!