How to plot 3D pdf without meshgrid

17 visualizzazioni (ultimi 30 giorni)
N/A
N/A il 11 Mar 2020
Commentato: N/A il 13 Mar 2020
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')

Risposte (1)

darova
darova il 11 Mar 2020
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 Commento
N/A
N/A il 13 Mar 2020
No, it doesn't give what I want. I need 3D surface as an output with my samples. Your code give just points.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by