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 (2025). iscaller (https://www.mathworks.com/matlabcentral/fileexchange/13164-iscaller), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 | updated discription |