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);