-
Notifications
You must be signed in to change notification settings - Fork 0
/
BestAngles.m
executable file
·41 lines (40 loc) · 946 Bytes
/
BestAngles.m
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
function [theta, c, details] = BestAngles(x,y, varargin)
%[theta, c, details] = BestAngles(x,y, varargin)
%
j = 1;
test = 0;
while j <= length(varargin)
if strncmpi(varargin{j},'hartigan',3)
test = test+2;
end
j = j+1;
end
if test == 0
test = 1;
end
a = 0:pi/36:pi;
for j = 1:length(a)
xy = xyrotate(x,y,a(j));
if bitand(test,2)
dip(j) = HartigansDipTest(sort(xy(:,1)));
end
if bitand(test,4)
[aa,bb] = FindDip(xy(:,1));
mydip(j) = bb.dipsize(1);
end
if bitand(test,1)
coeff(j) = (1+skewness(xy(:,1)).^2)./(kurtosis(xy(:,1).^1.3)+3);
end
stds(j) = std(xy(:,1));
ystds(j) = std(xy(:,2));
end
if test == 2
coeff = dip;
end
[c, j] = max(coeff);
theta = a(j);
details.coeff = coeff;
details.angles = a;
details.xy = xyrotate(x,y,a(j));
details.stds = stds;
details.ystds = ystds;