calledby(depth)

バージョン 1.1.0.0 (2.49 KB) 作成者: Dave Stanley
Queries the source of function calls
ダウンロード: 67
更新 2015/6/23

ライセンスの表示

out = calledby(func_name)
OVERVIEW
Queries the source of a function call, with variable depth, returning
the calling function's name.
FORMS
out = calledby
out = calledby(depth)
DESCRIPTION
out = calledby
Returns the name of the calling function
out = calledby(depth)
Returns the name of the calling function at depth depth

INPUTS
depth - Depth of calling function to search. 0=current function,
1=calling function (default), etc..

OUTPUTS
out - Name of calling function or queried function. Returns 'root' if
called from base workspace

EXAMPLES
Example 1
calledby % Returns error
calledby(0) % Returns root
calledby(1) % Returns error

Example 2
% Drop this into a script called test1.m
function test1
calledby
fprintf('Should return root. Press any key... \n'); pause

calledby(1)
fprintf('Should return root. Press any key... \n'); pause

calledby(0)
fprintf('Should return test1. Press any key... \n'); pause

test2
end
function test2
calledby
fprintf('Should return test1. Press any key... \n'); pause

calledby(1)
fprintf('Should return test1. Press any key... \n'); pause

calledby(2)
fprintf('Should return root. Press any key... \n'); pause

calledby(0)
fprintf('Should return test2. Press any key... \n'); pause

%calledby(3)
%fprintf('Should return error \n');
end

See also function is_calledby(func_name)
http://www.mathworks.com/matlabcentral/fileexchange/51280-is-calledby-func-name-

引用

Dave Stanley (2024). calledby(depth) (https://www.mathworks.com/matlabcentral/fileexchange/51281-calledby-depth), MATLAB Central File Exchange. 取得済み .

MATLAB リリースの互換性
作成: R2007a
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
カテゴリ
Help Center および MATLAB AnswersTest Scripts についてさらに検索
タグ タグを追加

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
バージョン 公開済み リリース ノート
1.1.0.0

Added link to partner function, is_calledby.m

1.0.0.0