User`s guide

2 How to Create a GUI with GUIDE
Program the Simple GUIDE GUI
In this section...
“Add Code to the Simple GUIDE GUI” on page 2-28
“Generate Data to Plot” on page 2 -28
“Program the Pop-Up Menu” on page 2-31
“Program the Push Buttons” on page 2-33
Add Code to the Simple GUIDE GUI
When you saved your GUI in the previous topic, “Save the GUI Layout” on
page 2-25, GUIDE created two files: a FIG-file
simple_gui.fig that contains
the GUI layout and a file,
simple_gui.m, that contains the code that controls
how the GUI behaves. The code consists of a set of MATLAB functions (that
is, it is not a script). But the GUI did not respond because the functions
containnostatementsthatperformactionsyet. Thistopicshowsyouhowto
addcodetothefiletomaketheGUIdothings. Thefollowingthreesections
describe the steps to take:
Generate Data to Plot
This topic shows you how to generate the data to be plotted when the GUI
user clicks a button. The opening function generates this data by calling
MATLAB functions. The opening function, which initializes a GUI when it
opens, is the f irst callback in every GUIDE -generated GUI code file.
In this example, you add code that creates three data sets to the opening
function. The code uses the MATLAB functions
peaks, membrane,andsinc.
1 Display the opening function in the MATLAB editor. If the file
simple_gui.m is not already open in your editor, open it by selecting
Editor from the GUIDE View menu. In the editor, click the function icon
on the toolbar, then select simp le_gui_OpeningFcn in the pop-up
menu that displays.
2-28