Instructor:
Bill Miller
Dynamic Neuroimaging Laboratory
415.502.3726
http://dnl.ucsf.edu
1. Concepts: Interface, Responding to graphics events
figure %creates normal figure window - can still type on command line
dialog %creates a modal figure - can't type on command line
For example, the following code creates a pushbutton on a figure with the name "Click Me" and the Callback string "disp hello". Clicking the button causes the string to be executed by MatLab just as if the command had been typed at the command line. (To try it, copy this code, paste it at the MatLab prompt, and press return).
uicontrol('style','pushbutton','string','Click Me','callback','disp hello')
In another example, the closereq can be used in a callback to close the figure window:
uicontrol('style','pushbutton','string','Quit','callback','closereq')
Note that this technique of executing strings as MatLab commands is also commonly done in non-GUI programs using the eval command. We haven't encountered eval in previous sessions, so see its help information to learn more.
2. Structure of a GUI-program: a reliable approach
Overall design approach:
This method of creating GUI programs has several advantages:
3. GUIfft: An illustrative example
The following example, GUIfft.m illustrates the above style of making a GUI program. GUIfft has 3 functionalities:
GUIfft's interface consists of a figure window containing:
To implement the above functionality and user interface, GUIfft.m contains a top-level function (GUIfft) and four subfunctions:
| Name | Called by | Purpose |
| GUIfft(action) | User (command line) or graphics callbacks | Decide which sub-function to call depending input argument |
| CreateGUI | GUIfft when action='create' | Creates GUI interface |
| LoadFile | GUIfft when action='loadfile' | Load and plot raw data |
| doFFT | GUIfft when action='dofft' | Compute and plot FFT of raw data |
| Threshold | GUIfft when action='threshold' | Create and place a threshold line on the axis |
GUIfft.m includes extensive commenting to help you understand each line of each function.
4. Live response to mouse motion: two examples
In the above example program GUIfft, the "ButtonDownFcn" property of the axis used to generate a callback for creating a new threshold line when the mouse is clicked somewhere inside the axis. Holding the mouse button down while moving the mouse has no effect in this case. However, it is possible to obtain just such "live" movable behavior, by employing the following:
The following programs employ the above properties to create and manipulate movable lines on an axis (which can be used for thresholding or finding peaks, etc.):
The live action technique involves dynamically resetting the callback strings of the above properties, and is a bit beyond explaining here. Take a look at the help information provided with these functions, and the code itself to see how the behavior is acheived.