【问题标题】:Mesh Plot Problems in MatlabMatlab中的网格图问题
【发布时间】:2016-01-17 09:17:21
【问题描述】:

我想绘制meshc 等高线图,但未按我的意愿绘制等高线。

x = linspace(P(1),P(2)); %// x axis
y = linspace(P(3),P(4)); %// y axis
[X1 Y1] = meshgrid(x,y); %// all combinations of x, y
%[X1,Y1] = meshgrid(1:.125:3); 
Z1 = mvnpdf([X1(:) Y1(:)],mu,sigma); %// compute Gaussian pdf
Z2 = reshape(Z1,size(X1)); %// put into same size as X, Y
meshc(X1,Y1,Z2); 
%axis([1 3 1 3 -5 10]);
axis([P(1) P(2) P(3) P(4) -5 10])

上面的代码是这样画的:

但我希望它是这样的:

我该怎么做?

【问题讨论】:

  • “所需”图像中显示的图与多元高斯完全不同 - 看起来更像是几个加权多元高斯的总和。如果仅使用一次调用 mvnpdf 来计算值,则无法绘制它。我认为您的问题缺少有关您实际想要实现的目标的一些重要细节。
  • 我换了第二张图。我的问题是轮廓的位置。我希望它远离第二张图片中的高斯

标签: matlab plot mesh


【解决方案1】:

要获得所需的图之间的距离,您只需从Z2 矩阵中减去一些数字。我不明白为什么 Matlab 会以这种方式划分图,但它确实有效:

P = [1 3 1 3];
mu = [2 1.1];
sigma = [.09 .003; ...
         .003 .002];

x = linspace(P(1),P(2)); %// x axis
y = linspace(P(3),P(4)); %// y axis
[X1 Y1] = meshgrid(x,y); %// all combinations of x, y
Z1 = mvnpdf([X1(:) Y1(:)],mu,sigma); %// compute Gaussian pdf
Z2 = reshape(Z1,size(X1)); %// put into same size as X1, Y1

Z2 = Z2 - 0.01;

meshc(X1,Y1,Z2); 

axis([P(1) P(2) P(3) P(4) -5 10])

也许您需要使用其他数字才能获得所需的结果。在我的示例中,我减去了一个小数,以避免更改 pdf-plot 范围。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-23
    • 2011-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多