I have N
functions in MATLAB and I can define them using strcat
, num2str
and eval
in a for loop. So without defining by hand I am able to define N
functions. Let N=4
and let them be given as follows:
f1=@(x) a1*x+1;
f2=@(x) a2*x+1;
f3=@(x) a3*x+1;
f4=@(x) a4*x+1;
Now I add these four functions and I can do this by hand as follows:
f=@(x)(f1(x)+f2(x)+f3(x)+f4(x));
Here I can do it by hand because I know that N=4
. However, in general I never know how many functions I will have. For all cases I cannot write a new function.
Is there any way to do this automatically? I mean if I give N=6
I am expecting to see MATLAB giving me this:
f=@(x)(f1(x)+f2(x)+f3(x)+f4(x)+f5(x)+f6(x));
Whenever I give N=2
then I must have the function f
, defined as follows:
f=@(x)(f1(x)+f2(x));
How can we do this?