Plot Histogram and PDF together
20 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Georgios Vamvakopoulos
el 12 de Ag. de 2016
Comentada: Star Strider
el 13 de Ag. de 2016
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 comentarios
dpb
el 12 de Ag. de 2016
Sure, see
doc hold % you want 'on' after the first plot to add the second to it
Respuesta aceptada
Star Strider
el 12 de Ag. de 2016
If you have the Statistics and Machine Learning Toolbox, use the histfit function.
3 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Histograms en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!