-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeanangle.m
More file actions
44 lines (40 loc) · 1.06 KB
/
meanangle.m
File metadata and controls
44 lines (40 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function [out] = meanangle(in,dim,sens);
%
% MEANANGLE will calculate the mean of a set of angles (in degrees) based
% on polar considerations.
%
% Usage: [out] = meanangle(in,dim)
%
% in is a vector or matrix of angles (in degrees)
% out is the mean of these angles along the dimension dim
%
% If dim is not specified, the first non-singleton dimension is used.
%
% A sensitivity factor is used to determine oppositeness, and is how close
% the mean of the complex representations of the angles can be to zero
% before being called zero. For nearly all cases, this parameter is fine
% at its default (1e-12), but it can be readjusted as a third parameter if
% necessary:
%
% [out] = meanangle(in,dim,sensitivity)
%
% Written by J.A. Dunne, 10-20-05
%
if nargin<3
sens = 1e-12;
end
if nargin<2
ind = min(find(size(in)>1));
if isempty(ind)
%This is a scalar
out = in;
return
end
dim = ind;
end
in = in * pi/180;
in = exp(i*in);
mid = mean(in,dim);
out = atan2(imag(mid),real(mid))*180/pi;
out(abs(mid)<sens) = nan;
out(out<0)=360+out(out<0);