function [x,y] = choose2dPoints(N,a) % Use: [x,y] = choose2dPoints(N,a) % Displays a plot in which the user can interactively select N data points in % 2-D where the boundary of the selection of data points is specified by the % axis variable a % Returns the x coordinates and y coordinates which can be saved in a % .mat file for later use by issuing the command save fileName x y. % Author: Grady Wright % Create the figure with the appropriate axis. figure, axis(a), hold on; % Instructions str = sprintf('Using the mouse, select the location of the data points\n you wish to include in your distribution. You must press \n enter after selecting each point. A counter will be printed \n to the console indicating what number of the data point you are\n currently selecting.'); str counter = 0; while (counter < N) try, [newx,newy] = ginput; x(counter+1) = newx(1); y(counter+1) = newy(1);... counter = counter+1, catch, 'Error - Select point then press enter', end; plot(x,y,'or'); end hold off; x = x'; y = y';