How can I fit histogram?

조회 수: 6 (최근 30일)
studentmatlaber
studentmatlaber 2021년 10월 29일
편집: studentmatlaber 2021년 11월 18일
I want to normalize my histogram. I know there are commands histogram(x, nbits, 'Normalization','probability') and histogram(x, nbits, 'Normalization','pdf'). But what is the difference between 'probability' and 'pdf'?

채택된 답변

the cyclist
the cyclist 2021년 10월 30일
편집: the cyclist 2021년 10월 30일
Answering the first part of your question ...
With probability normalization, the sum of the bin heights will be 1. With pdf normalization, the integral of the bins (i.e. the sum of the bin heights times widths) will be 1.
Here is a silly example that illustrates the difference:
rng default
N = 5000;
x = binornd(1,0.5,N,1)/2;
figure
histogram(x, 5, 'Normalization','probability')
figure
histogram(x, 5, 'Normalization','pdf')
Answering the second part of your question ...
I believe you can use histcounts to get the normalized bin counts, then fit those values with normfit:
[binCounts, binEdges] = histcounts(x, 5, 'Normalization','probability');
binCenters = (binEdges(1:end-1) + binEdges(2:end))/2;
[muHat,sigmaHat] = normfit(binCenters,binCounts)
muHat = 0.2500
sigmaHat = 0.1581
  댓글 수: 2
studentmatlaber
studentmatlaber 2021년 11월 1일
Thank you very much for your reply. However, after finding the mean and sigma values with the normfit, how do I draw the fit graph of it? I have uploaded my file in the question. I fit the histogram with "t location scale" with distribution fitter app. However I want to normalize it as "probability". I can find the mean and sigma value as you suggested, but how do I plot it later? I couldn't picture it in my head. I would be glad if you help.
the cyclist
the cyclist 2021년 11월 1일
You need to plot it according to the formula for a normal distribution. (See, e.g., this wikipedia page.)
You could just code that formula from scratch, but instead you could create a distribution object:
mu = 2;
sigma = 3;
pd_norm = makedist('Normal','mu',mu,'sigma',sigma)
pd_norm =
NormalDistribution Normal distribution mu = 2 sigma = 3
x = -3:0.01:7;
plot(x,pdf(pd_norm,x))

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by