MATLAB: How to put any variable name automatically

MATLABoptimizationstring

In this program,
a = 1 ;
b=2;
c = zeros(20,1);
d= zeros(20,1);
for k = 1:20
c(k) = (b+k)^2 + (a+k)^3;
d(k) = (b+k)^2 - (a+k)^3;
end
[maxobjective, iteration1] = max((c));
but i want to pre define objective function, means
[maxobjective, iteration1] = max((c)); or
[maxobjective, iteration1] = max((d));
put automatically like below.
objfun = c; %or d
a = 1 ;
b=2;
c = zeros(20,1);
d= zeros(20,1);
for k = 1:20
c(k) = (b+k)^2 + (a+k)^3;
d(k) = (b+k)^2 - (a+k)^3;
end
[maxobjective, iteration1] = max((objfun));

Best Answer

Use the same variable for both, but make it a cell array. And make objfun the index of the cell to use.