y = gauss(p,x) Compute values at x on a Gaussian shaped curve with parameters: p(1) = peak height p(2) = mean p(3) = sigma p(4) = optional zero offset eg: x=[-3:0.1:3]; plot(x,gauss([10,0.5,1.3],x)); NB - the parameter order is the reverse of that expected by Matlab funcs like quad - but swapping it doesn't help as quad refuses to pass forward anything but scalar parameters.
0001 function y = gauss(p,x, norm) 0002 % y = gauss(p,x) 0003 % 0004 % Compute values at x on a Gaussian shaped curve 0005 % with parameters: 0006 % 0007 % p(1) = peak height 0008 % p(2) = mean 0009 % p(3) = sigma 0010 % 0011 % p(4) = optional zero offset 0012 % 0013 % eg: x=[-3:0.1:3]; plot(x,gauss([10,0.5,1.3],x)); 0014 % 0015 % NB - the parameter order is the reverse of 0016 % that expected by Matlab funcs like quad - but swapping it doesn't 0017 % help as quad refuses to pass forward anything but 0018 % scalar parameters. 0019 0020 if(nargin==2) 0021 norm = 0; 0022 end 0023 0024 if(length(p)<4) 0025 p(4)=0; 0026 end 0027 0028 y=p(1)*exp(-(x-p(2)).^2/(2*p(3)^2))+p(4); 0029 0030 if(norm==1) 0031 y = y./sum(y); 0032 end