Choosing a function handle from a group of function handles

2 ビュー (過去 30 日間)
Mohammad Shojaei Arani
Mohammad Shojaei Arani 2022 年 7 月 29 日
Hello,
Assume that we have saved many function handles f_1_1, f_1_2,f_1_3, ..., f_2_1,f_2_2,f_2_3, .... in a folder. Now, assume also
that natural numbers m and n are given. Now, I want to define a function handle f as f = f_m_n . How to do this? (I mean, I want to
do this in a code in a for-loop).
Thanks,
Babak
  2 件のコメント
Voss
Voss 2022 年 7 月 29 日
Please explain what it means to save a function handle in a folder.
Have you saved a function handle (which is a class of variable) in a mat-file in a folder?
Have you saved a function (which is MATLAB code) in an m-file in a folder?
Something else?
Mohammad Shojaei Arani
Mohammad Shojaei Arani 2022 年 7 月 29 日
Sorry if my explanation was not enough.
The functions are saved as m-files. If I know that m=3, n=4 then I can manually type f = f_3_4. But, how
to do this in a for-loop?
The only think I can do is as bellow
filename = strcat(['f_' num2str(m) '_' num2str(m)]);
but then I get f = 'f_3_4' not f = f_3_4.
I hope I was clear?

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

採用された回答

Stephen23
Stephen23 2022 年 7 月 29 日
s = sprintf('f_%d_%d',m,n);
f = str2func(s);

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by