MATLAB: Does anyone know how to loop through a list of dynamic functions

evalfor loopMATLABneural networkwhile loop

Hello everyone,
I am trying to create a loop of functions, which basically loops through a list of functions; the reason is that I want to find the best training function for a particular neural network.
s.a = 'trainb';
s.b = 'trainbfg';
s.c = 'trainbfgc';
fn = fieldnames(s);
for n = 1:length(fn)
trainfn=['net.trainFcn=' s.(fn{n})];
trainfn;
I first set up a structure with the 3 different functions, trainb, trainbfg, and trainbfgc, then I hope to loop through the functions one by one so that I will pass 3 functions:
net.trainFcn = 'trainb';
net.trainFcn = 'trainbfg';
net.trainFcn = 'trainbfgc';
At the moment all this does is just prints the text and does not apply the functions, I have tried feval, eval having no success, any help would be greatly appreciated,

Best Answer

I would recommend using function handles instead of quoted function names. There is also no reason to use a structure.
s = {@trainb, @trainbfg, @trainbfgc};
for n = 1:length(s)
net.trainFcn = s{n};
%now invoke the training here
end