From: Rob Campbell on
Hi,

Say I write function "X" which I intend to be called by other Matlab functions. Is there a command I can insert into X which would report the name of the function that called X?

I don't want to have to pass the name of the caller function to X as an input variable. i.e. this would not be a suitable solution:
X(inArgA,inArgB,mfilename)

Cheers
From: Malcolm Lidierth on
Look at the dbstack function which gives you the entire calling sequence.
Regards
ML
From: Rob Campbell on
"Malcolm Lidierth" <ku.ca.lck(a)htreidil.mloclam> wrote in message <hrc5to$foq$1(a)fred.mathworks.com>...
> Look at the dbstack function which gives you the entire calling sequence.
> Regards
> ML

Nice one!
Thanks.
From: Steven Lord on

"Rob Campbell" <matlab(a)robertREMOVEcampbell.removethis.co.uk> wrote in
message news:hrc5cs$arl$1(a)fred.mathworks.com...
> Hi,
>
> Say I write function "X" which I intend to be called by other Matlab
> functions. Is there a command I can insert into X which would report the
> name of the function that called X?
> I don't want to have to pass the name of the caller function to X as an
> input variable. i.e. this would not be a suitable solution:
> X(inArgA,inArgB,mfilename)

How are you planning to use this functionality? If you're trying to throw
an error message "as though" it were coming from the caller function,
generate an MException and use its throwAsCaller method.

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/throwascallermexception.html

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


From: Rob Campbell on
Steven, for the record what I was doing was

function varargout=X(varargin)
if nargout>2
disp("you're using function X with the old output format")
end

Being able to report who called function X is just a nicety so that people know where to look when updating code. dbstack does what I needed.