-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpPck.m
146 lines (129 loc) · 3.2 KB
/
pPck.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
function Y_new=ppick(Y,varid);
%function Y_new=ppick(Y,varid);
%
%PJ : 22.10.97
%
%This code allows interactive elimination of points from a time-series
%plot with 1:size(Y,1) as x-variable and Y(:,varid) as y-variable.
%
%The output matrix Y_new is the same as the input, apart from the selected
%points which are given a value of -99
%
%A log file pick_log.m is also created, which can be run afterwards in
%MATLAB to reproduce Y_new from Y.
%
%INPUT
%Y : nxp matrix
%varid : column number of matrix to examine
%
%OUTPUT
%Y_new : updated matrix with -99 for dropped values
%
%EXAMPLE
% X00=ppick(X00,21);
% allows interactive elimination of strange values of variable 21
% of matrix X00
%!if (-e pick_log.m) mv pick_log.m pick_log.m_old
happy='N';
while happy=='N';
xo=(1:size(Y,1))';
yo=Y(:,varid);
Y_new=Y;
clf;
pplt(xo,yo,'ro');
title(['Variable ' num2str(varid)]);
xd=[];
yd=[];
a=[];
b=[];
%This is the outer loop, which you use to specify a new rectangle of points
but=0;
while 1==1;
fprintf(1,'Options : Input first point with LH button\n');
fprintf(1,' : End selection of points with RH button\n');
but=0;
[a,b,but]=ginput(1);
if but==3;
if size(xd,1)>0;
break;
else;
fprintf(1,'Error : no points selected! Terminating\n');
return;
end;
end;
while 1==1;
while 1==1;
but=0;
[a2,b2,but]=ginput(1);
if but==1;
break;
end;
if but==3 & size(a,1)==2;
break;
else;
fprintf(1,'You need to enter a second corner now\n');
end;
end;
if but==3;
break;
end;
if size(a,1)==1;
a=[a;a2]; b=[b;b2];
else;
if size(a,1)==2;
a=[a(2);a2];b=[b(2);b2];
else;
fprintf(1,'Error : how did you get here? Terminating\n');
return;
end;
end;
fprintf(1,'Corners of rectangle are :\n');
fprintf(1,'(%d,%d)\n',[sort(a) sort(b)]');
t1=xo>=min(a)&xo<=max(a)&yo>=min(b)&yo<=max(b);
if sum(t1)>0;
fprintf(1,'You have highlighted %d points:\n',sum(t1));
fprintf(1,'(%d,%d)\n',[xo(t1==1) yo(t1==1)]');
pplt(xo,yo,'ro');
title(['Variable ' num2str(varid)]);
if size(xd,1)>0;
pplt(xd,yd,'bo');
end;
pplt(xo(t1==1),yo(t1==1),'go');
drawnow;
else
fprintf(1,'No points in rectangle!\n');
end;
end;
if sum(t1)>0;
xd=[xd;xo(t1==1)];
yd=[yd;yo(t1==1)];
pplt(xd,yd,'bo');
end;
drawnow;
end;
clf;
tmp=yo;
tmp(xd)=-99;
pplt(xo,tmp,'ro');
title(['Variable ' num2str(varid)]);
fprintf(1,'You are going to drop %d points:\n',size(xd,1));
fprintf(1,'(%d,%d) ',[xd yd]');
fprintf(1,'\n');
happy=fprintf('Happy? (Y=RH button /N=LH button)\n');
[junk1,junk2,but]=ginput(1);
if but==3;
happy='Y';
end;
if but==1;
happy='N';
end;
end;
fprintf(1,'Eliminating highlighted observations\n');
Y_new(xd,varid)=-99;
fid=fopen('pick_log.m','a');
id_drop=sort(xd);
fprintf(fid,'X([');
fprintf(fid,'%d ',id_drop);
fprintf(fid,'],%d)=-99;',varid);
fprintf(fid,'\n');
fclose(fid);