


CALLERFILE Name of calling M-file.
When called from within an M-file, CALLERFILE returns a string
containing the name of the preceding M-file on the call stack. If the
M-file was invoked directly from the command line (or if CALLERFILE is
itself invoked directly from the command line), CALLERFILE returns an
empty string.
P = CALLERFILE('fullpath') returns the full path and name of the
M-file preceding the M-file in which the call occurs, without the
extension.
If CALLERFILE is called with any argument other than 'fullpath', it
behaves as if it were called with no argument.
See also DBSTACK, INPUTNAME, MFILENAME.

0001 function caller = callerfile(option) 0002 %CALLERFILE Name of calling M-file. 0003 % When called from within an M-file, CALLERFILE returns a string 0004 % containing the name of the preceding M-file on the call stack. If the 0005 % M-file was invoked directly from the command line (or if CALLERFILE is 0006 % itself invoked directly from the command line), CALLERFILE returns an 0007 % empty string. 0008 % 0009 % P = CALLERFILE('fullpath') returns the full path and name of the 0010 % M-file preceding the M-file in which the call occurs, without the 0011 % extension. 0012 % 0013 % If CALLERFILE is called with any argument other than 'fullpath', it 0014 % behaves as if it were called with no argument. 0015 % 0016 % See also DBSTACK, INPUTNAME, MFILENAME. 0017 0018 stack = dbstack; % get the call stack 0019 0020 if (length(stack) > 2) % if it goes beyond the requesting m-file 0021 [p,caller] = fileparts(stack(3).name); 0022 if ((nargin > 0) && (strcmp(option, 'fullpath'))) 0023 caller = [p caller]; 0024 end 0025 else 0026 caller = ''; 0027 end 0028