EDIT:
In response to BruceWarrior's comment below, histfit
will normalize the data for you... just replace x
with your data. If you want to know how to normalize a histogram yourself such that it is a probability density, see my answer to that very question. Note that the accepted answer will not give you a probability density (i.e., the area under the curve will not be 1).
You can use the gamrnd
function to generate random variables with a Gamma distribution for a given shape parameter a
and scale parameter b
. You can then call histfit
on this data to fit the Gamma distribution to the normalized histogram. Here's an example:
x=gamrnd(1,2,1000,1);
histfit(x,50,'gamma')
a=1,b=2

a=2, b=2
