How do I get a list of currently executing functions?

조회 수: 9 (최근 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;
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
Steven Lord
Steven Lord 2020년 12월 14일
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 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개)

카테고리

Help CenterFile Exchange에서 Object Save and Load에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by