Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to get the name of the caller?

Subject: How to get the name of the caller?

From: Mateusz

Date: 22 Nov, 2009 21:05:07

Message: 1 of 3

Hi,

I try to get the name of the caller function from the callee's side. Is it possible to do that in Matlab?

For instance:
function = funF()
myCall()
end

and then myCall prints out 'funF'.

Best,
M.M.

Subject: How to get the name of the caller?

From: Matt Fig

Date: 22 Nov, 2009 21:17:03

Message: 2 of 3

See the help for:

mfilename

Subject: How to get the name of the caller? dbstack

From: Jeff

Date: 23 Nov, 2009 04:50:08

Message: 3 of 3

"Matt Fig" <spamanon@yahoo.com> wrote in message <hec9of$ok0$1@fred.mathworks.com>...
> See the help for:
>
> mfilename

To add a little detail (in case you're as obtuse as I am):

function = funF()
myCall(mfilename)
end

function myCall(caller)
caller
end

This works only if funF is in a file named funF.m.

You might have better luck with dbstack, which returns the call chain. I think you can get what you want with dbstack(1) and then you must figure out how to parse the output. The output is delivered in an nx1 struct which I have no idea how to parse (seeing as how I'm a newbie to Matlab), and the first element of that structure seems to contain what you want.

Good luck,
-Jeff

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us