function out=drawfig3(cc,axxis) % Like ginput, but also draws and closes the polygon. % Two optional inputs: color/plotstyle like 'co', and % axis, a 1x4 vector passed to the command axis -- to % freeze the axes at the current scaling call drawfig % with the second argument "axis". % % While drawfig creates a 2xn matrix, drawfig3 creates % a 3xn marix with ones in the third row. % disp('Left mouse button picks points.') disp('Rite mouse button picks last point.') if nargin==0 cc='m-'; axis([-5,5,-5,5]); elseif nargin==1 axis([-5,5,-5,5]); else axis(axxis); end; hold on n=1; [points(1,1),points(2,1),but]=ginput(1); points(3,1)=1; plot(points(1,1),points(2,1),cc); while but ==1 n=n+1 [points(1,n),points(2,n),but]=ginput(1) points(3,n)=1; plot(points(1,n-1:n),points(2,n-1:n),cc); end; %automatically close the polgon n=n+1; points(:,n)=points(:,1); plot(points(1,n-1:n),points(2,n-1:n),cc); out=points;