0001 function [X,Y,polygon] = UISelect
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 hold on;
0025 X = [];
0026 Y = [];
0027 polygon = [];
0028 last = false;
0029
0030 while ~last,
0031
0032 [x,y,button] = ginput(1);
0033 switch button,
0034 case 1,
0035
0036 X(end+1,1) = x;
0037 Y(end+1,1) = y;
0038 case 2,
0039
0040 last = true;
0041 if ~isempty(X),
0042 X(end+1,1) = X(1);
0043 Y(end+1,1) = Y(1);
0044 end
0045 case 3,
0046
0047 if ~isempty(X),
0048 X(end) = [];
0049 Y(end) = [];
0050 end
0051 end
0052
0053 if isempty(polygon),
0054 polygon = plot(X,Y);
0055 else
0056 warning('off','MATLAB:hg:line:XDataAndYDataLengthsMustBeEqual');
0057 set(polygon,'XData',X);
0058 set(polygon,'YData',Y);
0059 warning('on','MATLAB:hg:line:XDataAndYDataLengthsMustBeEqual');
0060 end
0061 end
0062
0063 hold off;