File Exchange

image thumbnail

iscaller

version 1.0.0.0 (788 Bytes) by Eduard van der Zwan
Determine the caller function

0 Downloads

Updated 04 Jan 2007

No License

Sometimes I would like a function to do something different from what it normally would do when it is called by a certain function. With ISCALLER you can determine this certain function:

ISCALLER Determine caller function.
TF = ISCALLER(S) returns a true if the function containing ISCALLER is called by the function named S
TF = ISCALLER(S1,S2,...) returns a true if the function containing ISCALLER is called by the function named S1, S2 or ...
S = ISCALLER returns the name of the caller function in string S

Examples:
We have three caller functions:

function caller1
%CALLER1 calles example function
calledFunction

function caller2
%CALLER2 calles example function
calledFunction

function caller3
%CALLER3 calles example function
calledFunction

All calling the following function:

function calledFunction
%CALLEDFUNCTION Finds out by which function it is called

%iscaller with string input returns true or false
disp('Example1:')
if iscaller('caller1','caller2')
disp('calledFunction is called by caller1 or caller2')
else
disp('calledFunction is not called by caller1 or caller2')
end

%iscaller without input returns name of caller
disp('Example2:')
switch iscaller
case 'caller1'
disp('calledFunction is called by caller1')
case 'caller2'
disp('calledFunction is called by caller2')
case 'caller3'
disp('calledFunction is called by caller3')
end

If we now run CALLER1, CALLEDFUNCTION returns:
Example1:
calledFunction is called by caller1 or caller2
Example2:
calledFunction is called by caller1

If we run CALLER2:
Example1:
calledFunction is called by caller1 or caller2
Example2:
calledFunction is called by caller2

And if we run CALLER3
Example1:
calledFunction is not called by caller1 or caller2
Example2:
calledFunction is called by caller3

Cite As

Eduard van der Zwan (2019). iscaller (https://www.mathworks.com/matlabcentral/fileexchange/13164-iscaller), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (2)

Kazuya Mishima

It's simple, but very good and extremely useful. Good job!!!

S Guy

Perfect Caller for all my private telephone calls to girls and no one has to know that i have called the phone. So to say, they don't know as i did. Why to call? Waf. Smokey guy.

Updates

1.0.0.0

updated discription

MATLAB Release Compatibility
Created with R14SP3
Compatible with any release
Platform Compatibility
Windows macOS Linux