circmean.m 573 B

123456789101112131415161718192021222324252627
  1. function cm=circmean(ph)
  2. % Synopsis
  3. % cm=circmean(ph)
  4. % Desription:
  5. % cm is the circular mean or mean direction of the phase data in
  6. % ph (angular data) in radians
  7. % ignores NaN
  8. % for ma matrix, calculates the mean for every column
  9. [rows,cols]=size(ph);
  10. if(rows==1 & cols>1)
  11. ph=ph';
  12. [rows,cols]=size(ph);
  13. end;
  14. for(c=1:cols)
  15. C=sum(cos(ph(:,c)), 'omitnan');
  16. S=sum(sin(ph(:,c)), 'omitnan');
  17. t=atan(S/C);
  18. if (C<0)
  19. cm(c)=t+pi;
  20. else
  21. if (S<0)
  22. cm(c)=t+2*pi;
  23. else
  24. cm(c)=t;
  25. end;
  26. end;
  27. end;