You can do it with only additions to your code
F1 = @(a)length(a);
F2 = @(b)sum(b);
F3 = @(c)min(c);
X=rand(1,100);
Myfuns={'F1','F2','F3'};
for ii = 1:length(Myfuns)
eval(['Myfuns{ii} = @(x)', Myfuns{ii}, '(x)']);
end
for i=1:length(Myfuns)
Y(i)=Myfuns{i}(X);
end
If the functions are contained in files that exist on the path, then you can use str2fcn instead of eval
Myfuns = cellfun(@str2func, Myfuns, 'UniformOutput', false);
The best is to define the function handles directly:
Myfuns={@(x)F1(x),@(x)F2(x),@(x)F3(x)};
Best Answer