3D Plot of Probability Density Functions using normpdf and line function
23 views (last 30 days)
Show older comments
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

0 Comments
Answers (1)
Prahlad Gowtham Katte
on 25 Jan 2022
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
0 Comments
See Also
Categories
Find more on Lighting, Transparency, and Shading in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!