MATLAB Answers


Problem in finding PDF of a set of samples

Asked by may
on 30 Sep 2013
Latest activity Commented on by Image Analyst
on 1 Oct 2013

I want to get PDF of a set of samples, A, from its histogram:

[n,x] =hist(A,Number_bins);

when I use the following code:


with different number of bins I get different results, to fix it I use this code


but some of numbers in pdf would be greater than one! (the probability should not be greater than one)

I really don't understand where the problem is. I would appreciate if you you could help me. Thank you.


Log in to comment.

1 Answer

Answer by Image Analyst
on 30 Sep 2013

Of course the PDF is different if you have different bin sizes. But most important is how you plan on using the PDF. What do you plan on doing with it? I think n/sum(n) is fine - you just have to know what you're dealing with when it comes time to use it. It tells you the probability of a sample falling into that bin.


I want to get probability density function of a set of samples, to do so I want to use histogram and then convert it to PDF. So I need to find the PDF representing the PDF of the sample, this should be independent of number of bins.

I edited the question, thanks.

Don't divide by the diff. And of course the PDF will vary according to the number of bins. Computers are digital - you can't have an infinite number of bins. It can't be continuous. It must be quantized and since the number of counts in the quantized pdf must equal the number of elements in your array, the value per bin must be different. My other question, about what you plan on doing with it, remains unanswered.

Log in to comment.

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!