필터 지우기
필터 지우기

Plot Histogram and PDF together

조회 수: 10 (최근 30일)
Georgios Vamvakopoulos
Georgios Vamvakopoulos 2016년 8월 12일
댓글: Star Strider 2016년 8월 13일
Hello everyone, I just wanted to know, if there is a way to plot Histogram and probability density function in one graph, as I wanted to check if the pdf agrees with my histogram. Thank you in advance :)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%Tree Diameter %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Tree Diameter histogram
L = 0:0.1:0.6;
load Tree_Diameter.mat
figure;
histc(Tree_Diameter,L)
bar(L,histc(Tree_Diameter,L),'histc')
xlabel('Diameter (m)'); ylabel('Frequency');
title('Tree Diameter Histogram')
% Tree Diameter Probability (lognormal)
pd = fitdist(Tree_Diameter,'lognormal')
y = pdf(pd,L)*0.1;
figure;
plot(L,y,'LineWidth',1)
xlabel('Tree Diameter (m)'); ylabel('Probability');
title('Tree Diameter')
% Tree Diameter PDF (lognormal)
mu = -1.61825;
sigma = 0.457151;
x = (0) : (sigma / 100) : (mu + 5 * sigma);
pdflognpdf = lognpdf(x, mu, sigma)/10; %/10
figure;
plot(x, pdflognpdf,'g');
xlabel('Diameter (m)'); ylabel('Pdf');
title('PDF for Tree Diameter');
  댓글 수: 2
dpb
dpb 2016년 8월 12일
Sure, see
doc hold % you want 'on' after the first plot to add the second to it
Georgios Vamvakopoulos
Georgios Vamvakopoulos 2016년 8월 12일
Thanks for replying but that's not what I need. I need to put them in the same graph. Just like this one;

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2016년 8월 12일
If you have the Statistics and Machine Learning Toolbox, use the histfit function.
  댓글 수: 3
Georgios Vamvakopoulos
Georgios Vamvakopoulos 2016년 8월 13일
Thank you :)
Star Strider
Star Strider 2016년 8월 13일
My pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by