BioNB 442: Lab 3
GUI design.
Introduction.
You will build a Matlab program to convert mouse clicks into x,y coordinates,
plot the points, connect them with a line, and save them to disk. This program
is sort of a stripped down version of lab data processing program.
Procedure:
You will need to look up information on the following functions:
ginput
-- captures mouse-clicks to an array.
The following code fragment captures mouse-clicks and plots each as a cross.
for i=1:numpts
[x(i),y(i)]=ginput(1);
plot(x(i),y(i),'kx');
hold on;
end
uisetcolor
-- opens a dialog box to specify a color.
uiputfile
-- opens a dialog box to specify a ouput file name.
The following code fragment shows how to get a file and and path name, then
use the save function to save two variables in plain-text format.
[filename,pathname]=uiputfile;
save (strcat(pathname,filename), 'x', 'y', '-ascii');
errordlg
-- opens a dialog box to give an error message.
Assignment
- Write a program with uicontrols approximately like those shown in the following
image.
- The Capture button starts the ginput function to collect the number
of points specified in the NumPts edit box. If the NumPts edit box contains
anything which is not a number or contains a number less than 1, then
an appropriate error dialog box must appear when this button is pushed.
As each mouse-click occurs, the program should plot the new point.
- The erase button erases the axes.
- The Connect button draws lines between the points collected by the capture
button. If no points have yet been captured, pushing this button must
cause an appropriate error dialog box to appear.
- The save button causes a uiputfile dialog box to appear. The x,y data
which have been captured are stored to the file name specified in the
dialog box. If no points have yet been captured, pushing this button must
cause an appropriate error dialog box to appear.
- The NumPts edit field contains the number of points to be captured as
mouse-clicks..
- The field to the right of it contains a string which will set the color
of the line when the Connect button is pressed.
- The Set bkgnd color button causes a uisetcolor dialog box to appear.
After a color is chosen in the dialog box, the axes background color is
set to the new color. If the cancel button is pushed in the uisetcolor
dialog box, the axes color should not change.
After a few points have been captured, the line color changed to black,
and the background color changed to blue the figure might look like
Your written lab report should include:
- The source code of the program you wrote with enough comments in the code
so that you and I can tell what you did.
- An image of the user interface you built showing some captured points.
August 2000 Copyright Cornell university