You can minimize a function using fminunc
like this:
x = linspace(-2,2,1000);
f0 = -x.^2;
ftest1 = @(a) a(1)*exp(-a(2)*x.^2);
fmin1 = @(a) trapz(x,(ftest1(a) - f0).^2);
[a1,fval] = fminunc(fmin1,rand(1,2));
plot(x,f0,x,ftest1(a1));
Is there a similar way to do this if you'd like to minimize with respect to two different (vector) variables?:
x = linspace(-2,2,1000);
f0 = -x.^2;
ftest2 = @(a,b) a(1)*exp(-b(1)*x.^2) + a(2)*exp(-b(2)*x.^2);
fmin2 = @(a,b) trapz(x,(ftest2(a,b) - f0).^2);
%[a2,b2,fval] = fminunc(...