3D Plot of Probability Density Functions using normpdf and line function

5 ビュー (過去 30 日間)
alex535
alex535 2022 年 1 月 8 日
回答済み: Prahlad Gowtham Katte 2022 年 1 月 25 日
I am trying to plot consecutive PDFs(Probability Density Function) using the line function in a 3D plot. I am able to plot the PDFs in 2D plot. However, may I please get some corrections/suggestions for the following code for the 3D plot. I am trying to show peak probability on vertical axis for t iterations.Thank you.
sigma = 30;
mu = 230;
t = 5;
for i = 1:1:t
if mu <= 230*5
s6=6*sigma;
x_pdf_1 = [-700:700];
y1 = normpdf(x_pdf_1,mu,sigma);
figure(1)
hold on
l=line(x_pdf_1,y1);
figure(2)
plot3(l,mu,t)
mu = mu+30;
end
end
2D Plot Result

回答 (1 件)

Prahlad Gowtham Katte
Prahlad Gowtham Katte 2022 年 1 月 25 日
Hi
I understand that you’re trying to plot consecutive PDFs using 3D plot. Following code snippet might help to resolve the issue.
sigma = 30;
mu = 230;
t = 5;
for i = 1:1:t
if mu <= 230*5
s6=6*sigma;
x_pdf_1 = [-700:700];
y1 = normpdf(x_pdf_1,mu,sigma);
figure(1)
hold on
l=line(x_pdf_1,y1);
figure(2)
plot3(x_pdf_1,y1,i*(ones(length(x_pdf_1)))) %Plotting a 3d plot in iteration i.
hold on %Making sure the plots would be on same figure
mu = mu+30;
end
end
The following link might give you a more detailed explanation of 3D plots.
Hope it answers your query.
Thanks

Community Treasure Hunt

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

Start Hunting!

Translated by