circ_dist.m 680 B

12345678910111213141516171819202122232425262728
  1. function r = circ_dist(x,y)
  2. %
  3. % r = circ_dist(alpha, beta)
  4. % Pairwise difference x_i-y_i around the circle computed efficiently.
  5. %
  6. % Input:
  7. % alpha sample of linear random variable
  8. % beta sample of linear random variable or one single angle
  9. %
  10. % Output:
  11. % r matrix with 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 size(x,1)~=size(y,1) && size(x,2)~=size(y,2) && length(y)~=1
  22. error('Input dimensions do not match.')
  23. end
  24. r = angle(exp(1i*x)./exp(1i*y));