How to plot 3D pdf without meshgrid

8 次查看(过去 30 天)
N/A
N/A 2020-3-11
评论: N/A 2020-3-13
I need a 3D pdf plot without meshgrid.
I wrote this code but I don't know how to do it without meshgrid.
Can you help me please
mu=[0 1];
cov=[1 0.7; 0.7 2];
rng('default');
R = mvnrnd(mu,cov,10);
plot(R(:,1),R(:,2),'+');
x1 = -4:0.2:4;
x2 = -4:0.2:8;
[X1,X2] = meshgrid(x1,x2);
X = [X1(:) X2(:)];
y = mvnpdf(X,mu,cov);
y = reshape(y,length(x2),length(x1));
surf(x1,x2,y)
caxis([min(y(:))-0.5*range(y(:)),max(y(:))])
axis([-4 4 -4 8 0 0.15])
xlabel('x1')
ylabel('x2')
zlabel('Probability Density')

回答(1 个)

darova
darova 2020-3-11
Without meshgrid
x = 1:3;
y = 1:4;
[X,Y] = meshgrid(x,y)
X1 = repmat(x,[length(y) 1])
Y1 = repmat(y(:),[1 length(x)])
Or you mean something else?
  1 个评论
N/A
N/A 2020-3-13
No, it doesn't give what I want. I need 3D surface as an output with my samples. Your code give just points.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by