2011-03-03 128 views
0

如何使用mesh()绘制高斯在2D,这个MATLAB函数里面......摹轮廓Matlab的

function G(Mean,Cov,c) 

icov = inv(Cov); 
det_cov = det(Cov); 
const = 1/(2*pi*sqrt(det_cov)); 

xx = linspace(Mean(1)-3*sqrt(Cov(1,1)),Mean(1)+3*sqrt(Cov(1,1))); 
yy = linspace(Mean(2)-3*sqrt(Cov(2,2)),Mean(2)+3*sqrt(Cov(2,2))); 

[x y] = meshgrid(xx,yy); 
mx=x-Mean(1); 
my = y-Mean(2); 

z=const*exp(-0.5*(icov(1,1)*mx.^2+icov(2,1)*mx.*my +icov(2,1)*my.*mx+icov(2,2)*my.^2)); 
contour(x,y,z,c); 

回答

3

只需用mesh取代contour

此外,尽量不要使用MeanCov作为变量名称。 meancov是Matlab的函数,虽然拼写稍有不同,但您仍然在设置一些难以发现的错误。