-
Notifications
You must be signed in to change notification settings - Fork 0
/
myHist.m
50 lines (42 loc) · 860 Bytes
/
myHist.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
42
43
44
45
46
47
48
49
50
function [Hn,Xn] = myHist(Data)
nBins = round(length(Data) / 15);
[H,X] = hist(Data, nBins);
[Max,IMax] = max(H);
sumH = sum(H);
curSum = 0.0;
T = 0.990;
i1 = IMax;
i2 = IMax;
I1 = i1;
I2 = i2;
stop1 = 0;
stop2 = 0;
while ((i1>=1) || (i2<=length(X)))
if (i1~=i2)
if (stop1~=1) curSum = curSum + H(i1); end
if (stop2~=1) curSum = curSum + H(i2); end
else
curSum = curSum + H(i1);
end
if (curSum <= sumH * T)
I1 = i1;
I2 = i2;
if (i1>1)
i1 = i1 - 1;
else
stop1 = 1;
end
if (i2<length(X))
i2 = i2 + 1;
else
stop2 = 1;
end
else
break;
end
end
Xn = X(I1:I2);
Hn = H(I1:I2);
%plot(Xn,Hn + max(H));
%hold on;
%plot(X,H,'r')