% Allows user to interactively choose points on a graph.  
% Right clicking with the mouse ends input session.

function out=graphical_input()
   
xmin=-8; 
xmax=8; 
ymin=-8; 
ymax=8;

% close window if it is open
close;

%create axes with min and max values
axis([xmin,xmax,ymin,ymax]);

% make sure graph is not cleared after each point plotted
hold on;

% turn on grid
grid on;

title('Use left mouse button to choose points, right mouse button to stop.')

xnew=[]; 
ynew=[]; 
button=1;
i=1;

while button~=3
   % get data point plus button press
   [xnew,ynew,button]=ginput(1);

   % make sure right mouse button not clicked
   if button~=3 

      % plot new point to the graph
      plot(xnew,ynew,'+')
      x_points(i,1)=xnew;
      y_points(i,1)=ynew;
      i=i+1;
   end
end

out(:,1)=x_points;
out(:,2)=y_points;
