Escolar Documentos
Profissional Documentos
Cultura Documentos
2-5
2 In the Quick Start dialog, select the Blank GUI (Default) template.
Click OK to display the blank GUI in the Layout Editor, as shown in the
following figure.
2-6
3 Display the names of the GUI components in the component palette. Select
Preferences from the MATLAB File menu. Then select GUIDE > Show
names in component palette, and click OK. The Layout Editor then
appears as shown in the following figure.
2-7
2-8
push button from the component palette at the left of the Layout Editor
and drag it into the layout area. Position them approximately as shown in
the following figure.
2-9
Arrange the components as shown in the following figure. Resize the axes
component to approximately 2-by-2 inches.
2-10
3 Make these settings in the Alignment Tool, as shown in the following figure:
2-11
4 Click OK. Your GUI now looks like this in the Layout Editor.
2-12
After you have added the appropriate text, the GUI will look like this in the
Layout Editor.
2-13
2 In the layout area, select the top push button by clicking it.
3 In the Property Inspector, select the String property and then replace the
4 Click outside the String field. The push button label changes to Surf.
2-14
5 Select each of the remaining push buttons in turn and repeat steps 3 and 4.
Label the middle push button Mesh, and the bottom button Contour.
2-15
3 Replace the existing text with the names of the three data sets: Peaks,
2-16
4 When you are done, click OK. The first item in your list, Peaks, appears in
dialog box that displays, replace the existing text with the phrase
Select Data.
2-17
3 Click OK. The phrase Select Data appears in the static text component
Completed Layout
In the Layout Editor, your GUI now looks like this and the next step is to
save the layout. The next topic, Saving the GUI Layout on page 2-19, tells
you how to do this.
2-18
3 GUIDE opens a Save As dialog box in your current directory and prompts
4 Browse to any directory for which you have write privileges, and then enter
the filename simple_gui for the FIG-file. GUIDE saves both the FIG-file
and the M-file using this name.
5 If the directory in which you save the GUI is not on the MATLAB path,
GUIDE opens a dialog box, giving you the option of changing the current
2-19
working directory to the directory containing the GUI files, or adding that
directory to the top or bottom of the MATLAB path.
the GUI. It also opens the GUI M-file in your default editor.
The GUI is active. You can select a data set in the pop-up menu and click
the push buttons. But nothing happens. This is because there is no code
in the M-file to service the pop-up menu and the buttons. The next step
is to program the GUI. The next topic, Programming a Simple GUI on
page 2-21, shows you how to do this.
2-20
2-21
The cursor moves to the opening function, which already contains this code:
% --- Executes just before simple_gui is made visible.
function simple_gui_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject
handle to figure
% eventdata
% handles
% varargin
2-22
2 Create data for the GUI to plot by adding the following code to the opening
The first six executable lines create the data using the MATLAB functions
peaks, membrane, and sinc. They store the data in the handles structure,
which is passed as an argument to all callbacks. Callbacks for the push
buttons can retrieve the data from the handles structure.
The last two lines create a current data value and set it to peaks, and then
display the surf plot for peaks. The following figure shows how the GUI
now looks when it first displays.
2-23
The GUI M-file opens in the editor if it is not already open, and the cursor
moves to the pop-menu callback, which already contains this code:
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject
% eventdata
% handles
2-24
2-25
1 Display the Surf push button callback in the M-file editor. Right-click the
Surf push button in the Layout Editor to display a context menu. From
that menu, select View Callbacks > Callback.
The GUI M-file opens in the editor if it is not already open, and the cursor
moves to the Surf push button callback, which already contains this code:
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject
% eventdata
% handles
2 Add the following code to the callback immediately after the comment that
begins % handles...
% Display surf plot of the currently selected data.
surf(handles.current_data);
3 Repeat steps 1 and 2 to add similar code to the Mesh and Contour push
button callbacks.
Add this code to the Mesh push button callback, pushbutton2_Callback:
2-26
Your GUI is ready to run. The next topic, Running the GUI on page 2-28,
tells you how to do that.
2-27
GUI is on your MATLAB path or in your current directory, you can also
run it by typing its name, simple_gui, at the prompt. The GUI looks like
this when it first displays:
2-28
2 In the pop-up menu, select Membrane, then click the Mesh button. The
2-29