


DRAW Draws points on the current plot, returning their locations.
If n, the number of points is not given, DRAW stops drawing
when you hit right button on mouse
Usage: [x,y]=draw(n);
n = points to draw
x = returned x locations drawn points
y = returned y locations drawn points

0001 function [x,y]=draw(n); 0002 % DRAW Draws points on the current plot, returning their locations. 0003 % If n, the number of points is not given, DRAW stops drawing 0004 % when you hit right button on mouse 0005 % 0006 % Usage: [x,y]=draw(n); 0007 % n = points to draw 0008 % x = returned x locations drawn points 0009 % y = returned y locations drawn points 0010 % 0011 if nargin==0 0012 n=2000; 0013 end 0014 disp('Click left button to draw, right button to quit') 0015 i=1; 0016 [x(1,1),x(1,2),ibutton]=ginput(1); 0017 line(x(1,1),x(1,2),'color','cyan','Marker','o'); 0018 while (i<n)&(ibutton==1) 0019 i=i+1; 0020 [xx,yy,ibutton]=ginput(1); 0021 if(ibutton==1), 0022 x(i,1)=xx; 0023 x(i,2)=yy; 0024 line(x( (i-1):i,1),x((i-1):i,2), 'color','cyan','Marker','o'); 0025 line(x(i,1),x(i,2), 'color','cyan','Marker','o'); 0026 end 0027 end 0028 if nargout==2 0029 y=x(:,2); 0030 x=x(:,1); 0031 end 0032 0033