-
Notifications
You must be signed in to change notification settings - Fork 0
/
lasso.m
56 lines (42 loc) · 1.4 KB
/
lasso.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
function [selx,sely,indexnr]=lasso(x,y)
% lasso - enables the selection/encircling of (clusters of) events in a scatter plot by hand
% using the mouse
%
% Input: x,y - a set of points in 2 column vectors.
% Output: selx,sely,indexnr - a set of selected points in 3 column vectors
%
% Note: After the scatter plot is given, selection by mouse is started after any key press.
% This is done to be able to ZOOM or CHANGE AXES etc. in the representation before selection
% by mouse.
% Encircling is done by pressing subsequently the LEFT button mouse at the requested positions
% in a scatter plot.
% Closing the loop is done by a RIGHT button press.
%
% T.Rutten V2.0/9/2003
plot(x,y,'o')
las_x=[];
las_y=[];
c=1;
key=0;
% disp('press a KEY to start selection by mouse, LEFT mouse button for selection, RIGHT button closes loop')
% while key==0
% key=waitforbuttonpress;
% pause(0.2)
% end
while c==1
[a,b,c]=ginput(1);
las_x=[las_x;a];las_y=[las_y;b];
line(las_x,las_y)
drawnow
end;
las_x(length(las_x)+1)=las_x(1);
las_y(length(las_y)+1)=las_y(1);
line(las_x,las_y)
pause(.2)
in=inpolygon(x,y,las_x,las_y);
ev_in=find(in>0);
selx=x(ev_in);
sely=y(ev_in);
figure,plot(x,y,'b.',selx,sely,'g.');
legend(num2str([length(x)-length(selx);length(selx)]));
indexnr=ev_in;