I want to create a mesh from 2 plotted 1D PDF plots

2 次查看(过去 30 天)
I want to create a mesh given the two one dimensional pdf plot whose code is as follows:
mu1=3.4*10^6;
sigma1=0.5*10^6;
X1=normrnd(mu1,sigma1,[200,1]);
sorted_X1=sort(X1);
Y1=normpdf(sorted_X1,mu1,sigma1);
figure
plot(sorted_X1,Y1)
mu2=3;
sigma2=2;
X2=normrnd(mu2,sigma2,[200,1]);
sorted_X2=sort(X2);
Y2=normpdf(sorted_X2,mu2,sigma2);
prior_deltau=zeros(200,1);
for i=1:200
if sorted_X2(i)<=0
prior_deltau(i)=0;
else
prior_deltau(i)=Y2(i);
end
end
figure
plot(sorted_X2,prior_deltau)
With X2 on x-axis and Y2 on y-axis

采纳的回答

Ashutosh Singh Baghel
Hi Dhruwal,
I understand you wish to plot a 3d mesh with the vectors 'prior_deltaa' and 'Y1' as y-coordinates of points when 'sorted_X2' and 'sortedX1' are x-coordinates of points, respectively. To resolve this issue, the following is one approach -
mu1=3.4*10^6;
sigma1=0.5*10^6;
X1=normrnd(mu1,sigma1,[200,1]);
sorted_X1=sort(X1);
Y1=normpdf(sorted_X1,mu1,sigma1);
% figure
% plot(sorted_X1,Y1)
mu2=3;
sigma2=2;
X2=normrnd(mu2,sigma2,[200,1]);
sorted_X2=sort(X2);
Y2=normpdf(sorted_X2,mu2,sigma2);
prior_deltau=zeros(200,1);
for i=1:200
if sorted_X2(i)<=0
prior_deltau(i)=0;
else
prior_deltau(i)=Y2(i);
end
end
% figure
% plot(sorted_X2,prior_deltau)
[X,Y] = meshgrid(sorted_X2,sorted_X1);
Z = Y1*prior_deltau';
mesh(X,Y,Z);
Refer to the following MATLAB Documentation page on 'meshgrid' and 'mesh'.

更多回答(0 个)

类别

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