ProbDist1D.m 605 B

12345678910111213141516171819
  1. function [P bins] = ProbDist1D(x, nbins);
  2. %PROBDIST1D
  3. % Usage: [P bins] = ProbDist1D(x, nbins);
  4. %
  5. % This function calculates the discrete probability distribution for a
  6. % variable that is in a one dimensional phase space. It is simply a
  7. % normalized histogram using 'hist', so nbins can take any form that hist
  8. % can take, although it does not allow for all the other hist options.
  9. %Written by Dan Valente
  10. %September 2007
  11. [H bins] = hist(x, nbins);
  12. N = sum(sum(H));
  13. binsize = bins(3)-bins(2);
  14. P = H./(N*binsize); %divide by total points and binsize to normalize correctly
  15. return;