Running Functions in For Loop

2 ビュー (過去 30 日間)
emary
emary 2015 年 7 月 1 日
回答済み: Muthu Annamalai 2015 年 7 月 1 日
If I have functions Force_1 through Force_10, how can I write a for loop that runs all functions?

採用された回答

Muthu Annamalai
Muthu Annamalai 2015 年 7 月 1 日
You can develop a solution using str2func() to turn the string into a function handle.
First generate a list of 10 strings, and store their handles
for count = 1:10
function_names{count} = sprintf('Force_%d',count);
function_handles{count} = str2func( function_names{count} );
end
To evaluate any function use the command,
feval
HTH

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by