circ_dist2.m 721 B

123456789101112131415161718192021222324252627282930313233343536
  1. function r = circ_dist2(x,y)
  2. %
  3. % r = circ_dist(alpha, beta)
  4. % All pairwise difference x_i-y_j around the circle computed efficiently.
  5. %
  6. % Input:
  7. % alpha sample of linear random variable
  8. % beta sample of linear random variable
  9. %
  10. % Output:
  11. % r matrix with pairwise differences
  12. %
  13. % References:
  14. % Biostatistical Analysis, J. H. Zar, p. 651
  15. %
  16. % PHB 3/19/2009
  17. %
  18. % Circular Statistics Toolbox for Matlab
  19. % By Philipp Berens, 2009
  20. % berens@tuebingen.mpg.de - www.kyb.mpg.de/~berens/circStat.html
  21. if nargin < 2
  22. y = x;
  23. end
  24. if size(x,2)>size(x,1)
  25. x = x';
  26. end
  27. if size(y,2)>size(y,1)
  28. y = y';
  29. end
  30. r = angle(repmat(exp(1i*x),1,length(y)) ...
  31. ./ repmat(exp(1i*y'),length(x),1));