简体   繁体   English

在Matlab中使用ksdensity的3d图

[英]3d plot with ksdensity in matlab

I have a problem in matlab. 我在Matlab中有问题。

I used a ksdensity function on a vector of deltaX, which was my computed X minus actual X. And I did the same on deltaY. 我在deltaX的向量上使用了ksdensity函数,这是我计算出的X减去实际X。我在deltaY上也做了同样的事情。

Then I used plot on that data. 然后,我对该数据进行了绘图。 This gave me two 2d plots. 这给了我两个二维绘图。

As I have two plots showing how (in)accurate was my system in computing X and Y (something like gaussian bell it was). 正如我有两幅图显示的那样,我的系统在计算X和Y时的准确性(类似于高斯钟形)。 Now I would like to have one plot but in 3d. 现在我想在3D中绘制一个图。 The code was just like that: 代码就是这样:

    [f,xi] = ksdensity(deltaX);
            figure;
            plot(xi,f)

Ok what I'm about to show is probably not the correct way to visualize your problem, mostly because I'm not quite sure I understand what you're up to. 好的,我要展示的可能不是可视化您的问题的正确方法,主要是因为我不确定我是否了解您的工作。 But this will show you an example of how to make the Z matrix as discussed in the comments to your question. 但这将向您显示一个示例,说明如何制作Z矩阵,如对问题的评论中所述。

Here's the code: 这是代码:

x = wgn(1000,1,5);%create x and y variables, just noise
y = wgn(1000,1,10);
[f,xi] = ksdensity(x);%compute the ksdensity (no idea if this makes real-world sense)
[f2,xi2] = ksdensity(y);

%create the Z matrix by adding together the densities at each x,y pair
%I doubt this makes real-world sense
for z=1:length(xi)
for zz = 1:length(xi2)
        Z(z,zz) = f(z)+f2(zz);
    end
end

figure(1)
mesh(xi,xi2,Z)

Here's the result: 结果如下:

在此处输入图片说明

I leave it up to you to determine the correct way to visualize your density functions in 3D, this is just how you could make the Z matrix. 我要由您决定确定在3D模式下可视化密度函数的正确方法,这就是制作Z矩阵的方法。 In short, the Z matrix contains the plot elevation at each x,y coordinate. 简而言之,Z矩阵包含每个x,y坐标处的绘图高程。 Hope this helps a little. 希望这有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM