2

I know that I can fit a histogram with a gamma distribution in this way:

histfit(data,bins-number,'gamma');figure(gcf);

And I know too that I can normalize a histogram with histnorm. But how can I create a normalized gamma distribution with its histogram?

Any idea or suggestion? Thanks for any help!

Sam Roberts
  • 23,951
  • 1
  • 40
  • 64
Bruce_Warrior
  • 1,161
  • 2
  • 14
  • 24

1 Answers1

3

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

enter image description here

a=2, b=2

enter image description here

Community
  • 1
  • 1
abcd
  • 41,765
  • 7
  • 81
  • 98
  • But I have a real data, I don't want generate one with random number following a gamma distribution. I want normalizate (i mean, with summations of all probabilities equal to one), with my array of data and after create a histogram with this distribution normalizated and after make the fitting – Bruce_Warrior Jun 22 '11 at 15:19
  • @BruceWarrior: Please see my edit above. I've added a link to an answer showing how to normalize a histogram. – abcd Jun 22 '11 at 15:34