Running Functions in For Loop
조회 수: 2 (최근 30일)
이전 댓글 표시
If I have functions Force_1 through Force_10, how can I write a for loop that runs all functions?
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!