calling subfunctions with handle
3 ビュー (過去 30 日間)
古いコメントを表示
Hi! :)
I have funcntion with a subfunction containing a handle:
function h= tellsoner
x= 0;
h= @legg_til_soner;
function y= legg_til_soner;
x= x+1
y=x
end
end
% ......................I am wondering how I can call the subfunction to accumulate the values or am I supposed to call the parent function always..?
0 件のコメント
回答 (1 件)
Benjamin Kraus
2021 年 12 月 15 日
編集済み: Benjamin Kraus
2021 年 12 月 15 日
You can call a function from a function handle by appending parentheses to the end of the variable name, even if there are no input arguments.
fh = tellsoner;
out = fh()
out = fh()
out = fh()
function h = tellsoner
x = 0;
h = @legg_til_soner;
function y = legg_til_soner
x = x+1
y = x
end
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Tables についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!