function err = gauss_errfn(fitparams,x,y); % % function err = gauss_errfn(fitparams,x,y); % % Returns the error, err, between the z-gaussian function and the % input data. Assumes the input data is of the form where x is % the grid, and y is the Gaussian. % % Input variable fitparams should be of the following form: % % fitparams = [A, xo, sigma], % % where we are fitting to a gaussian of the form: % % y = A*exp(-(x-xo)^2 / (2*sigma^2)) % % % Written by Miles A. Sundermeyer, 2/1/06 % parse fitparams A = fitparams(1); xo = fitparams(2); sigma = fitparams(3); % compute the function associated with the fit params yfit = A*exp(-(x-xo).^2 / (2*sigma^2)); vecscale = 3e+2; if(0) % plot this as a check figure(99) clf plot(x,y,'bo'); hold on plot(x,yfit,'r-'); xlabel('x') ylabel('y') axis([min(x(:)) max(x(:)) min([min(y(:)) 0]) max(y(:))]) drawnow end % compute the error between the fitted and actual fields err = abs([y(:)-yfit(:)]);