Calling unknown function names

2 ビュー (過去 30 日間)
Joel Duncan
Joel Duncan 2020 年 11 月 9 日
編集済み: Stephen23 2020 年 11 月 9 日
APSCalcset1 = str2func('HeatFluxCoolant_V1')
APSCalcset2 = str2func('HR_V1')
for funcrun = 1:100
if exist(['APSCalcset' num2str(funcrun)],'var')
processed = feval(eval(['APSCalcset' num2str(funcrun)]),tempdata);
end
end
So I know this is not ideal, attempting to use eval with you guys doesn't seem to go over well. I just can't figure out how to get the function handle in feval dynamically without it. The number of functions with the handle naming convention will be unknown.
  3 件のコメント
Joel Duncan
Joel Duncan 2020 年 11 月 9 日
I don't know that I will have 100, it's just a placeholder for a possible number. The attempt here is to allow other users of the code to add their own call functions by following the consecutive number naming convention for their function handle variables. The 'processed' variable will be a structure which continues to grow with information until all call functions are complete before sending the compilation back to the parent script for integration into another dataset.
Can the funcArray hold the APSCalcset# variables and have them execute in the same manner? I can't seem to get it to work with the function handle variables. Using 'str2func' is necessary to allow users to create their own unique call function names and update version names later on.
Stephen23
Stephen23 2020 年 11 月 9 日
編集済み: Stephen23 2020 年 11 月 9 日
"I don't know that I will have 100, it's just a placeholder for a possible number."
Just use one cell array, it can have any size... or even change size.
"The attempt here is to allow other users of the code to add their own call functions by following the consecutive number naming convention for their function handle variables."
Using a cell array would be simpler, more expandable, more efficient, easier to debug, etc.
"I can't seem to get it to work with the function handle variables."
Put them into a cell array. Call them. Geoff Hayes already showed you how.

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

回答 (0 件)

カテゴリ

Help Center および File ExchangePerformance and Memory についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by