ProbDist2D.m 935 B

1234567891011121314151617181920212223242526
  1. function [P bins] = ProbDist2D(x, nbins);
  2. %PROBDIST2D
  3. % Usage: [P bins] = [P bins] = ProbDist2D(x, nbins);
  4. %
  5. % This function calculates the discrete probability distribution for a
  6. % variable that is in a two dimensional phase space. Because the variable
  7. % exists in a two dimensional phase space, we have to bin in x^2
  8. % (equivalent to dividing P by x). The function simply calculates a
  9. % normalized histogram using 'hist', so nbins can take any form that hist
  10. % can take, although it does not allow for all the other hist options.
  11. %Written by Dan Valente
  12. %September 2007
  13. [H bins] = hist(x.^2, nbins);
  14. N = sum(sum(H));
  15. binsize = bins(3)-bins(2);
  16. P = H./(N*binsize);
  17. %now transform bins back to the unsquared locations. This is really only
  18. %for conviencence, by no means is it necessary. If this line is commented
  19. %out, then the plot is simply P vs. x^2 instead of P vs. x
  20. bins = sqrt(bins);
  21. return;