JointDist.m 724 B

1234567891011121314151617181920212223242526272829303132
  1. function [P bins] = JointDist(x,y,nbins)
  2. %JOINTDIST
  3. % Usage: [P bins] = JointDist(x,y,nbins)
  4. %
  5. %This function calculates the joint distribution of the variables x and y.
  6. %It is simply a normalized histogram using hist3. nbins can take any form
  7. %of bins that hist3 can take, but no other hist3 options.
  8. %Written by Dan Valente
  9. %October 2007
  10. %ensure x and y are both column matrices
  11. [nrowsx,ncolsx] = size(x);
  12. if (ncolsx ~= 1)
  13. x = x';
  14. end
  15. [nrowsy,ncolsy] = size(y);
  16. if (ncolsy ~= 1)
  17. y = y';
  18. end
  19. [H bins] = hist3([x y], nbins);
  20. N = sum(sum(H));
  21. binsize_x = bins{1}(3)-bins{1}(2);
  22. binsize_y = bins{2}(3)-bins{2}(2);
  23. P = H./(N*binsize_x*binsize_y); %Normalize correctly
  24. return;