How do I get a list of currently executing functions?

10 Ansichten (letzte 30 Tage)
Harry Dymond
Harry Dymond am 14 Dez. 2020
Kommentiert: Harry Dymond am 14 Dez. 2020
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 Kommentare
Steven Lord
Steven Lord am 14 Dez. 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 am 14 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by