MATLAB: How to dynamically change a function to solve a list of problems

cellcell arrayfunctionMATLABmatlab function

Hello everybody. I have a list of problems that need to be solve by a list of algorithm. In fact, I have 28 problems where each of them needs to be solved by each of 10 algorithms. So I need create a routine that change automatically the name of problem and algorithm. How can I do it?
Let suppose, prob1, prob2, prob3, etc the problems who needs to be solved by the algorithms alg1, alg2, alg3, etc. Where alg1, alg2, alg3, etc are functions.
The problemas are given test problems. To solve, for example, the prob1 using the alg1, I need to do
[M, jM] = alg1(@prob1)
My question is, how can I dinamically change the names of algorithms and problems such that all the problems are solved by all the algorithms?
I try put all algorithms in a 'cell array' like
alg = {'alg1','alg2','alg3'}
and all the problems in another 'cell array' like
prob ={@prob1,@prob2,@prob3}
and then do
for i = 1:numel(alg)
for j = 1: numel(prob)
[M,jM]=(alg{i})(prob{j}) % I think here is the problem.
end
end
but it didn't work.
Can anyone help me?
Thank you.

Best Answer

In some ways your question is strange because the solution is to use an array of functions handles instead of an array of function names. You're already using function handles for your problems (whatever these are) which is a bit unexpected. I would have thought that problems would be variables not functions.
alg = {@alg1, @alg2, @alg3}; %array of function handles
for i = 1:numel(alg)
for i = 1:numel(prob)
[M, jM] = alg{i}(prob{j}); %obviously you'd want to store the results in arrays/or cell arrays instead of overwriting them at each step of the loop
end
end