load gaussfit.dat g=gaussfit(:,1); h=gaussfit(:,2); plot(g,h,'ro--') hold on bestfit=fminsearch(@(x0) gafit(x0),[2 1]); xp=-3:.01:3; gauss=bestfit(1)*exp(-bestfit(2)*xp.^2); plot(xp,gauss,'g') %produce a vector which has the value of the gaussian fit % exactly at each dat pt g2=bestfit(1)*exp(-bestfit(2)*g.^2); plot(g,g2,'kd') error=E2(h,g2)