1 2 3 4 5 6 7 8 9 10 11
function [z] = fitGaussian1D(p,v,x) cx = p(1); wx = p(2); amp = p(3); background = p(4); zx = amp*exp(-2*(x-cx).^2./(wx^2)) - v - background; z = sum(zx.^2);