How to call a different function for each iteration of a loop?
7 views (last 30 days)
Show older comments
If I have created a set of functions with names corresponding to indices, How do I later call that function with the index I am on? e.g. in a "for" loop, call "minfunt1" on iteration 1, "minfunt2" on iteration 2, etc.?
0 Comments
Accepted Answer
Andrei Bobrov
on 3 Jun 2014
funcells = cell(15,1);
for jj=1:15
Minsum=minimize6(D0,D1,D2,D3,D4,D5,D6,D7,D8,Data104trans(jj,3:13));
a = sprintf('minfunt%d',jj);
matlabFunction(Minsum,'file',a);
funcells{jj} = str2func(a);
end
use your functions in loop
for jj = 1:15
[x1,x2,x3,x4,x5,x6,x7,x8,x9,]=loop5(funcells{jj},x1,x2,x3,x4,x5,x6,x7,x8,x9);
end
More Answers (1)
Image Analyst
on 3 Jun 2014
I don't understand how this is different than your prior answer in http://www.mathworks.com/matlabcentral/answers/132127#answer_139195 which I answered and you accepted.
3 Comments
Image Analyst
on 3 Jun 2014
How different are these functions? Totally different? Or are they very similar functions that you can just pass j into?
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!