フィルターのクリア

Execute a list of functions

14 ビュー (過去 30 日間)
Hg
Hg 2016 年 11 月 2 日
コメント済み: Hg 2016 年 11 月 2 日
How do I store a list of user-defined function in an array and execute it in a loop one by one?
[d] = func1(a),
[e] = func2(b),
[f] = func2(c) ...

採用された回答

Walter Roberson
Walter Roberson 2016 年 11 月 2 日
myfun = {@func1, @func2, @func2} ;
vars = {a, b, c};
for K = 1 : length(myfun)
result{K} = myfun{K}(vars{K});
end
  1 件のコメント
Hg
Hg 2016 年 11 月 2 日
Thank you!

サインインしてコメントする。

その他の回答 (1 件)

KSSV
KSSV 2016 年 11 月 2 日
編集済み: KSSV 2016 年 11 月 2 日
myfun = {'func1','func2','func3'} ; % write function names in a cell
d = feval(myfun{1},a) ; % calls first function
e = feval(myfun{2},b) ; % calls second function
f = feval(myfun{3},c) ; % calls third function
doc feval.
  1 件のコメント
Hg
Hg 2016 年 11 月 2 日
This also works but Walter's answer is closer (regarding looping)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by