function err = gaussianFunc(p,x,y,plot_handle,text_handle) % Calculates the sum of squared error between y and the predicted function, % which is the sum of a sinusoid and a 2nd order polynomial. % % This is the required format for a function to be minimized by 'fit.m': %1) All model parameters must be fields of the first input parameter (p) %2) The first output parameter must be the error value to be minimized predY = p.AA.*exp(-(x-p.CC).^2/(2*p.BB^2)); % % this function call above calls the model params. from the structure p % (called initP initially in main code) and also takes independent variable x % calculate chi-squared (this is what we want to minimize) by comparing to % actual dependent variable (i.e. the y-data to fit to) err = sum( (y-predY).^2); % deal with graphics update set(plot_handle,'YData',predY); txt=sprintf(' '); set(text_handle,'String',txt); drawnow