manipulate 2d gaussian in matlab

39 Views Asked by At

I wish to plot 2d gaussian in matlab, and here is the code and generated graph.

x=0:.02:1; y=x; 
r = 0.2; %set standard deviation
[X,Y]=meshgrid(x,y); 
Z=exp(-((X-0.5).^2+(Y-0.5).^2)/(2*r^2)); 
mesh(X,Y,Z) 
colormap([0 0 0]); 

enter image description here

Since we can get a 2d gaussian from multipying two 1d gaussian: enter image description here

I wish to do the same thing to "Z" in my code:

x=0:.02:1; y=x; 
r = 0.2; %set standard deviation
[X,Y]=meshgrid(x,y); 
Z=exp(-((X-0.5).^2)/(2*r^2)) * exp(-((Y-0.5).^2)/(2*r^2)); 
mesh(X,Y,Z) 
colormap([0 0 0]); 

But here is what I got: a flat plane enter image description here

I do not really understand why. Could someone shed some light? Thanks!

0

There are 0 best solutions below