Running Functions in For Loop

4 views (last 30 days)
emary on 1 Jul 2015
Answered: Muthu Annamalai on 1 Jul 2015
If I have functions Force_1 through Force_10, how can I write a for loop that runs all functions?

Accepted Answer

Muthu Annamalai
Muthu Annamalai on 1 Jul 2015
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} );
To evaluate any function use the command,

More Answers (0)


Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!