开发者

G Contour Matlab

开发者 https://www.devze.com 2023-02-14 17:33 出处:网络
How to use mesh() to draw gaussians in 2d, inside this Matlab function... functionG(Mean,Cov,c) icov = inv(Cov);

How to use mesh() to draw gaussians in 2d, inside this Matlab function...

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


Simply replace contour with mesh.

Also, try not to use Mean and Cov as variable names. mean and cov are Matlab functions, and while the spelling is slightly different, you're still setting yourself up for some hard-to-find bugs.

0

精彩评论

暂无评论...
验证码 换一张
取 消