简体   繁体   中英

3d plot with ksdensity in matlab

I have a problem in 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.

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). Now I would like to have one plot but in 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.

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. In short, the Z matrix contains the plot elevation at each x,y coordinate. Hope this helps a little.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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