Normalize histogram of normally distributed data

2 views (last 30 days)
How can I normalize a histogram of normally distributed points? I have tried using histnorm from the file exchange and a few other suggestions in the help forums, but the height of my bins are on the order of 10^4.
I am using normrand to distribute data points, but the height of the histogram (or height of the pdf when I use histfit) always depends upon the number of data points and the number of bins I use.

Answers (2)

Honglei Chen
Honglei Chen on 12 Mar 2013
You just need to normalize it toward the number of points
x = randn(1024,1)
[n,b] = hist(x)
Honglei Chen
Honglei Chen on 13 Mar 2013
Edited: Honglei Chen on 14 Mar 2013
Then what is your rule of normalization, normalize towards what?

Sign in to comment.

Tom Lane
Tom Lane on 14 Mar 2013
I would normalize it to area 1. The usual histogram has area equal to binwidth*sum(n), so divide by that. Probably binwidth=b(2)-b(1).
Peter Perkins
Peter Perkins on 27 Jun 2013
You want to compare a histogram to a PDF. Tom's suggestion is the correct one. The histogram integrates to binwidth*numObservations, the PDF to 1. The easiest thing to do is to scale your PDF by multiplying by binwidth*numObservations, but you can also call hist, get the bin counts, normalize them by dividing by binwidth*numObservations, and call bar.
If your PDF is a fit to the data, I'd recommend plotting the data and fitting the model using the dfittool GUI, which makes the plot your looking for (as well as many others) automatically.
Hope this helps.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!