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