MATLAB SIMULINK 7 - GRAPHICAL USER INTERFACE Uživatelský manuál
Procházejte online nebo si stáhněte Uživatelský manuál pro Software MATLAB SIMULINK 7 - GRAPHICAL USER INTERFACE. Creating Graphical User Interfaces Uživatelská příručka
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
ATLAB
Soubor PDF · ·
Shrnutí obsahu
Creating Graphical User Interfaces Version 7 The Language of Technical Computing
How to Contact The MathWorks: www.mathworks.com Web comp.soft-sys.matlab Newsgroup www.mathworks.com/contact_TS.html Technical support…
Revision History November 2000 Online only New for MATLAB 6.0 (Release12) June 2001 Online only Revised for MATLAB 6.1 (Release 12.1) July 2002 Online…
v Contents Getting Started About GUIs in MATLAB What Is a GUI? 1-2 How Does a GUI Work? 1-3 Where Do I Start? 1-4 Creating a GUI with GUIDE GUIDE: A…
vi Contents Generating Data to Plot 2-19 Programming the Pop-Up Menu 2-21 Programming the Push Buttons 2-23 Running the GUI 2-26 Creating a GUI…
vii Creating GUIs with GUIDE What Is GUIDE? 4-2 Laying Out a GUI 4-2 Programming the GUI 4-2 GUIDE Tools Summary 4-3 Preferences and Options GUIDE…
viii Contents Selecting a GUI Template 6-5 Accessing the Templates 6-5 Template Descriptions 6-6 Setting the GUI Size 6-12 Adding Components to the…
ix Saving and Running the GUI Naming a GUI and Its Files 7-2 The GUI Files 7-2 File and GUI Names 7-3 How to Assign Names 7-3 Renaming GUIs and GUI…
x Contents Callback Syntax and Arguments 8-11 Naming of Callback Functions 8-11 Changing Callback Names Assigned by GUIDE 8-12 Input Arguments 8-13…
xi Examples of GUIDE GUIs GUI with Multiple Axes 10-2 Techniques Used in the Example 10-2 View Completed Layout and Its GUI M-File 10-3 Design of the…
xii Contents The Contact Name Callback 10-38 The Contact Phone Number Callback 10-39 Paging Through the Address Book — Prev/Next 10-40 Saving Changes…
xiii Creating GUIs Programmatically Functions for Creating GUIs Introduction 11-2 Function Summary 11-3 Predefined Dialog Boxes 11-3 Creating…
xiv Contents Techniques Used in the Example 25 View the Completed GUI M-File 25 Subfunction Summary 26 M-File Structure 27 GUI Programming Techniques…
Getting Started These sections show you how to create a simple graphical user interface (GUI) using GUIDE, the MATLAB ® graphical user interface…
About GUIs in MATLAB What Is a GUI? (p. 1-2) Explains a graphical user interface (GUI) from a GUI user’s perspective. How Does a GUI Work? (p. 1-3)…
1 About GUIs in MATLAB 1-2 What Is a GUI? A graphical user interface (GUI) is a graphical display that contains devices, or components, that enable a…
How Does a GUI Work? 1-3 How Does a GUI Work? Each component, and the GUI itself, is associated with one or more user-written routines known as…
1 About GUIs in MATLAB 1-4 Where Do I Start? First you have to design your GUI. You have to decide what you want it to do, how you want the user to…
Creating a GUI with GUIDE GUIDE: A Brief Introduction (p. 2-2) Introduces GUIDE, the graphical user interface development environment. The Example…
2 Creating a GUI with GUIDE 2-2 GUIDE: A Brief Introduction GUIDE, the MATLAB Graphical User Interface development environment, provides a set of…
The Example: Simple GUI 2-3 The Example: Simple GUI This chapter shows you how to use GUIDE to create the example graphical user interface (GUI) which…
2 Creating a GUI with GUIDE 2-4 Laying Out a Simple GUI “Opening a New GUI in the Layout Editor” on page 2-4 “Setting the GUI Figure Size” on page 2-6…
Laying Out a Simple GUI 2-5 3 Display the names of the GUI components in the component palette. Select Preferences from the MATLAB File menu. Then…
2 Creating a GUI with GUIDE 2-6 Setting the GUI Figure Size Set the size of the GUI by resizing the grid area in the Layout Editor. Click on the…
Laying Out a Simple GUI 2-7 Adding the Components 1 Add the three push buttons to the GUI. For each push button, select the push button from the…
2 Creating a GUI with GUIDE 2-8 2 Add the remaining components to the GUI. A static text A pop-up menu An axes Arrange the components as shown in the…
Laying Out a Simple GUI 2-9 Aligning the Components You can use the Alignment Tool to align components with respect to one another, if they have the…
2 Creating a GUI with GUIDE 2-10 4 Click OK. Your GUI now looks like this is the Layout Editor.
Zobrazit všech 330 stran
Laying Out a Simple GUI 2-11 Adding Text to the Components Although the push buttons, pop-up menu, and static text show some text in the Layout…
2 Creating a GUI with GUIDE 2-12 2 In the layout area select the top push button by clicking it. 3 In the Property Inspector, select the String…
Laying Out a Simple GUI 2-13 4 The push button label changes to Surf when you click outside the String field. 5 Select each of the remaining push…
2 Creating a GUI with GUIDE 2-14 3 Replace the existing text with the names of the three data sets: Peaks, Membrane, and Sinc. Press Enter to move to…
Laying Out a Simple GUI 2-15 2 In the Property Inspector, click the button next to String. In the String dialog box that displays, replace the…
2 Creating a GUI with GUIDE 2-16 The Completed Layout In the Layout Editor, your GUI now looks like this and the next step is to save the layout. The…
Saving the GUI Layout 2-17 Saving the GUI Layout When you save a GUI, GUIDE creates two files, a FIG-file and an M-file. The FIG-file, with extension…
2 Creating a GUI with GUIDE 2-18 working directory to the directory containing the GUI files, or adding that directory to the top or bottom of the…
When you saved your GUI in the previous topic, “Saving the GUI Layout” on page 2-17, GUIDE created two files: a FIG-file simple_gui.fig that contains…
2 Creating a GUI with GUIDE 2-20 The cursor moves to the opening function which already contains this code: % --- Executes just before simple_gui is…
% Create the data to plot. handles.peaks=peaks(35); handles.membrane=membrane; [x,y] = meshgrid(-8:.5:8); r = sqrt(x.^2+y.^2) + eps; sinc = sin(r)./r…
2 Creating a GUI with GUIDE 2-22 index of the selected string. The pop-up menu callback reads the pop-up menu Value property to determine what item is…
It then uses a switch statement to make the selected data set the current data. The last statement saves the changes to the handles structure. %…
2 Creating a GUI with GUIDE 2-24 The GUI M-file opens in the editor if it is not already open, and the cursor moves to the Surf push button callback…
% Display contour plot of the currently selected data. contour(handles.current_data); 4 Save the M-file by selecting Save from the File menu. Your GUI…
2 Creating a GUI with GUIDE 2-26 Running the GUI In the previous topic, you programmed the pop-up menu and the push buttons. You also created data for…
Running the GUI 2-27 3 Try some of the other combinations before closing the GUI.
2 Creating a GUI with GUIDE
Creating a GUI Programmatically The Example: Simple GUI (p. 3-2) Describes the example to be constructed. Function Summary (p. 3-4) Lists the…
3 Creating a GUI Programmatically 3-2 The Example: Simple GUI This chapter shows you how to write a script that creates the example graphical user…
The Example: Simple GUI 3-3 Subsequent topics guide you through the process of creating the GUI. This process begins with “Creating a GUI M-File” on…
3 Creating a GUI Programmatically 3-4 Function Summary MATLAB provides a suite of functions for creating GUIs. This topic introduces you to the…
Function Summary 3-5 sin Sine; result in radians. sqrt Square root. surf 3-D shaded surface plot. Function Description
3 Creating a GUI Programmatically 3-6 Creating a GUI M-File Start by creating an M-file for the example GUI. 1 At the MATLAB prompt, type edit. MATLAB…
Laying Out a Simple GUI 3-7 Laying Out a Simple GUI This topic illustrates the basic steps for laying out a GUI. “Creating the Figure” on page 3-7…
3 Creating a GUI Programmatically 3-8 These statements use the uicontrol function to create the push buttons. Each statement uses a series of…
Laying Out a Simple GUI 3-9 5 Make your GUI visible by adding this command following the align command. set(f,'Visible','on') 6 This is what your…
3 Creating a GUI Programmatically 3-10 8 Type help simple_gui at the command line. MATLAB displays this help text. help simple_gui SIMPLE_GUI Select a…
Initializing the GUI 3-11 Initializing the GUI When you make the GUI visible, it should be initialized so that it is ready for the user. This topic…
3 Creating a GUI Programmatically 3-12 % Move the GUI to the center of the screen. movegui(f,'center') % Make the GUI visible. set(f,'Visible','on')…
Initializing the GUI 3-13 set([f,hsurf,hmesh,hcontour,htext,hpopup],... 'Units','normalized'); %Create a plot in the axes. current_data = peaks_data…
3 Creating a GUI Programmatically 3-14 Programming the GUI You use callbacks to program the GUI components. Callbacks are the functions that execute…
end The next topic, “Programming the Push Buttons” on page 3-15, shows you how to write callbacks for the three push buttons. Programming the Push…
3 Creating a GUI Programmatically 3-16 each component’s Callback property to specify the name of the callback with which it is associated. 1 To the…
Running the Final GUI 3-17 Running the Final GUI You have created the simple GUI. This topic shows you the final M-file and runs the GUI. “The Final…
3 Creating a GUI Programmatically 3-18 % Create the data to plot peaks_data = peaks(35); membrane_data = membrane; [x,y] = meshgrid(-8:.5:8); r =…
Running the Final GUI 3-19 end end % Push button callbacks. Each callback plots current_data in the % specified plot type. function…
3 Creating a GUI Programmatically 3-20 2 In the pop-up menu, select Membrane, then click the Mesh button. The GUI displays a mesh plot of the MATLAB…
Creating GUIs with GUIDE These sections describe how to create graphical user interfaces (GUIs) using GUIDE, the MATLAB ® graphical user interface…
What Is GUIDE? (p. 4-2) Introduces GUIDE, the MATLAB graphical user interface development environment. GUIDE Tools Summary (p. 4-3) Introduces the…
4 What Is GUIDE? 4-2 What Is GUIDE? GUIDE, the MATLAB Graphical User Interface development environment, provides a set of tools for creating graphical…
GUIDE Tools Summary 4-3 GUIDE Tools Summary The GUIDE tools are available from the Layout Editor shown in the figure below. The tools are called out…
4 What Is GUIDE? 4-4 Tool Use This Tool To: Layout Editor Select components from the Component Palette, at the left side of the Layout Editor, and…
GUIDE Tools Summary 4-5 You can also set preferences that apply to all GUIs at creation, and options that are GUI-specific. See Chapter 5…
4 What Is GUIDE?
Preferences and Options GUIDE Preferences (p. 5-2) MATLAB preferences for the GUIDE Layout Editor. GUI Options (p. 5-9) GUIDE options for individual…
5 Preferences and Options 5-2 GUIDE Preferences You can set preferences for the GUIDE Layout Editor by selecting Preferences from the MATLAB File…
GUIDE Preferences 5-3 Prompt to Save on Activate When you activate a GUI by clicking the Run button , a dialog box informs you of the impending save…
5 Preferences and Options 5-4 Prompt to Save on Export When you select Export from the Layout Editor File menu, a dialog box informs you of the…
GUIDE Preferences 5-5 All Other Preferences The GUIDE Layout Editor provides several other preferences. In the MATLAB Preferences dialog box, click…
5 Preferences and Options 5-6 The following topics describe the preferences in this dialog: “Show Toolbar” on page 5-6 “Show Names in Component…
GUIDE Preferences 5-7 Show Names in Component Palette Displays both icons and names in the component palette, as shown below. When unchecked, the…
5 Preferences and Options 5-8 Show File Extension in Window Title Displays the filename with its file extension in the Layout Editor window title. If…
GUI Options 5-9 GUI Options After opening a new GUI template in the Layout Editor, but before saving the GUI, you can configure various behaviors for…
5 Preferences and Options 5-10 Non-resizable — Users cannot change the window size (default). Proportional — MATLAB automatically rescales the…
GUI Options 5-11 Generate FIG-File and M-File Select Generate FIG-file and M-file in the GUI Options dialog if you want GUIDE to create both the…
5 Preferences and Options 5-12 GUIDE also adds a callback whenever you edit a callback routine from the Layout Editor’s right-click context menu and…
GUI Options 5-13 Note This option is available only if you first select the Generate FIG-file and M-File option. Generate FIG-File Only The Generate…
5 Preferences and Options 5-14 MATLAB versions 5.3 and earlier. See the guide command for more information. If you select Generate FIG-file only GUIDE…
Designing a GUI (p. 6-2) Things to think about when designing a GUI and references to other sources. Starting GUIDE (p. 6-4) Shows you all the ways to…
Designing a GUI Before creating the actual GUI, it is important to decide what it is you want your GUI to do and how you want it to work. It is…
Designing a GUI 6-3 Many web sites and commercial publications such as the following provide guidelines for designing GUIs: AskTog – Essays on good…
Starting GUIDE There are many ways to start GUIDE. You can start GUIDE: From the command line by typing guide. From the Start menu by selecting MATLAB…
Selecting a GUI Template 6-5 Selecting a GUI Template GUIDE provides several templates that you can modify to create your own GUIs. The templates are…
2 Optionally, name your GUI now by selecting Save on startup as and typing the name in the field to the right. GUIDE saves the GUI before opening it…
Selecting a GUI Template 6-7 Select the blank GUI if the other templates are not suitable starting points for the GUI you are creating, or if you…
When you run the GUI by clicking the Run icon , the GUI appears as shown in the following figure. When a user enters values for the density and volume…
Selecting a GUI Template 6-9 GUI with Axes and Menu The GUI with axes and menu template is shown in the following figure. When you run the GUI by…
You can select other plots in the pop-up menu. Clicking the Update button displays the currently selected plot on the axes. The GUI also has a File…
Selecting a GUI Template 6-11 Running the GUI displays the dialog box shown in the following figure: The GUI returns the text string Yes or No…
Setting the GUI Size Set the size of the GUI by resizing the grid area in the Layout Editor. Click on the lower-right corner and drag it until the GUI…
Setting the GUI Size 6-13 3 In the Property Inspector, click the + sign next to Position. The elements of the component’s Position property are…
Adding Components to the GUI “Available Components” on page 6-14 “Adding Components to the Layout Area” on page 6-18 “Assigning an Identifier to Each…
Adding Components to the GUI 6-15 When you first open the Layout Editor, the component palette contains only icons. To display the names of the GUI…
Component Description Push Button Push buttons generate an action when clicked. For example, an OK button might apply settings and close a dialog box.…
Adding Components to the GUI 6-17 Slider Sliders accept numeric input within a specific range by enabling the user to move a sliding bar, which is…
Adding Components to the Layout Area This topic tells you how to place components in the layout area and give each component a unique identifier. 1…
Adding Components to the GUI 6-19 the upper-left corner of the component to be, then setting the size of the control by dragging the cursor to the…
Adding a Component to a Panel or Button Group To add a component to a panel or button group, select the component in the component palette then move…
Adding Components to the GUI 6-21 If the component is not entirely contained in the panel or button group, it appears to be clipped in the layout…
You can use the Object Browser to determine the child objects of a panel or button group. “Viewing the Object Hierarchy” on page 6-62 tells you how.…
Adding Components to the GUI 6-23 1 Select the desired ActiveX control. The right panel shows a preview of the selected control. 2 Click Create, the…
See “ActiveX Control” on page 8-31 for information about programming a sample ActiveX control and an example. Assigning an Identifier to Each…
Adding Components to the GUI 6-25 Adding Text to the Components Many components have labels, lists, or other text that distinguishes them. You can set…
2 The component label changes when you click outside the String field. Pop-Up Menu Pop-up menus display a list of choices. 1 In the Property…
Adding Components to the GUI 6-27 1 In the Property Inspector, click the button next to String. In the String dialog box that displays, replace the…
1 In the Property Inspector, click the button next to String. In the String dialog box that displays, type the text that you want to display when that…
Adding Components to the GUI 6-29 2 The list appears in the list box in the Layout Area with the top-most item selected. 3 If the list box is not…
and Min properties so that Max-Min>1. For example, Max=2, Min = 0. Set the Value property to the index of the item you want selected when the list box…
Adding Components to the GUI 6-31 3 If you want to change the position of the title, select the button next to TitlePosition in the Property…
Press Ctrl+A to select all child objects of the figure. This does not select components that are child objects of panels or button groups. Click and…
Adding Components to the GUI 6-33 clipboard to the location of the last mouse click. It positions the upper left corner of the contents at the mouse…
Bring to Front — move the selected object(s) in front of nonselected objects (available from the right-click context menu, the Layout menu, or the…
Adding Components to the GUI 6-35 Dragging Components Select one or more components that you want to move, then drag them to the desired position and…
2 Click the + sign next to Position. The Property Inspector displays the elements of the Position property. 3 If you have selected only one component…
Adding Components to the GUI 6-37 Resizing Components You can resize components in one of the following ways: “Dragging a Corner of the Component” on…
3 Type the width and height you want the components to be. 4 Reset the Units property to characters. 5 Reset the Units property to its previous…
Aligning Components 6-39 Aligning Components The Layout Editor provides a number of features that facilitate alignment and distribution of components…
The alignment tool provides two types of alignment operations: Align — align all selected components to a single reference line. Distribute — space…
Aligning Components 6-41 All of the align options (vertical top, center, bottom and horizontal left, center, right) place the selected components with…
from left, distance from bottom, height, width]. The values are given in the units specified by the Units property of the component. 1 Select the…
Aligning Components 6-43 Use the Grid and Rulers dialog (select Grid and Rulers from the Tools menu) to: Control visibility of rulers, grid, and guide…
Guide lines used for horizontal alignment Click on the top or left ruler and drag the guide to the desired position Guide line used for vertical…
Setting Tab Order 6-45 Setting Tab Order A GUI’s tab order is the order in which components of the GUI are selected when a user presses the Tab key on…
To examine and change the tab order of the panel components, click the panel background to select it, then select Tab Order Editor in the Tools menu…
Setting Tab Order 6-47 arrow to move the component up or down in the list. If you set the tab order for the three components in the example to be 1…
Creating Menus GUIDE enables you to create two kinds of menus: “Menus for the Menu Bar” on page 6-49 — drop-down menus whose titles appear on the…
Creating Menus 6-49 Note In general, programming conventions described for components in Chapter 8, “Programming the GUI” also apply to menu items.…
Note By default, GUIDE selects the Menu Bar tab when you open the Menu Editor. 2 Click on the menu title to display a selection of menu properties in…
Creating Menus 6-51 Adding Items to a Menu Use the New Menu Item tool to create menu items that are displayed in the drop-down menu. 1 Add an Open…
You can also: Choose a keyboard accelerator for the menu item with the Accelerator pop-up menu. In combination with Ctrl, this is the keyboard…
Creating Menus 6-53 this field, GUIDE automatically sets the value using a combination of the Tag field and the GUI filename. See “Menu Item” on page…
Note See “Menu Item” on page 8-37 for information about programming menu items. Laying Out Three Menus The following Menu Editor illustration shows…
Creating Menus 6-55 When you run the GUI, the menu titles appear in the menu bar.
Context Menus A context menu is displayed when a user right-clicks on the object for which the menu is defined. The Menu Editor enables you to define…
Creating Menus 6-57 Adding Items to the Context Menu Use the New Menu Item tool to create menu items that are displayed in the context menu. 1 Add a…
2 Fill in the Label and Tag fields for the new menu item. For example, set Label to 'Blue background color' and set Tag to 'blue_background'. Click…
Creating Menus 6-59 Display a check next to the menu item when the menu is first opened by checking Check mark this item. A check indicates the…
In the GUI M-file, complete the callback subfunction for each item in the context menu. Each callback executes when a user selects the associated…
Creating Toolbars 6-61 Creating Toolbars GUIDE provides no tool to enable you do add a toolbar. However, you can add a toolbar by adding code to the…
Viewing the Object Hierarchy The Object Browser displays a hierarchical list of the objects in the figure, including both components and menus. As you…
Designing for Cross-Platform Compatibility 6-63 Designing for Cross-Platform Compatibility You can create GUIs that behave more consistently when run…
Specifying a Fixed-Width Font If you want to use a fixed-width font for a user interface control (uicontrol), set its FontName property to the string…
Designing for Cross-Platform Compatibility 6-65 systems, e.g., the standard shade of gray on the PC differs from that on UNIX, and may not match the…
Cross-Platform Compatible Units Cross-platform compatible GUIs should look correct on computers having different screen sizes and resolutions. Since…
Designing for Cross-Platform Compatibility 6-67 Units property back to characters, and the components’ Units properties to characters (nonresizable…
6 Laying Out a GUI
Saving and Running the GUI Naming a GUI and Its Files (p. 7-2) Describes the GUI files and how they are named. Saving a GUI (p. 7-5) Describes the…
7 Saving and Running the GUI 7-2 Naming a GUI and Its Files “The GUI Files” on page 7-2 “File and GUI Names” on page 7-3 “How to Assign Names” on page…
Naming a GUI and Its Files 7-3 File and GUI Names The M-file and the FIG-file that define your GUI must have the same name. This name is also the name…
7 Saving and Running the GUI 7-4 By selecting the Save or Save as options on the File menu GUIDE prompts you for a name before saving the GUI. The…
Saving a GUI 7-5 Saving a GUI This section tells you how to save a GUI you have constructed in GUIDE. “Ways to Save a GUI” on page 7-5 “Saving a New…
7 Saving and Running the GUI 7-6 Clicking the Save icon on the Layout Editor toolbar Selecting the Save or Save as options on the File menu Clicking…
Saving a GUI 7-7 Note that button groups and panels are introduced in MATLAB 7.0, and you should not use them in GUIs that you expect to run in…
7 Saving and Running the GUI 7-8 3 Change the directory if you choose, and then enter the name you want to use for the FIG-file. Be sure to choose a…
Saving a GUI 7-9 6 If you chose Yes in the previous step, GUIDE displays a dialog that asks if you want to replace the existing M-file or append to…
7 Saving and Running the GUI 7-10 Running a GUI Generally, you run your GUI by executing the M-file that GUIDE generates. This M-file contains the…
Running a GUI 7-11 If a GUI accepts arguments when it is run, they are passed to the GUI’s opening function. See “Opening Function” on page 8-15 for…
7 Saving and Running the GUI 7-12 Saving and Displaying Only the GUI Layout “Saving a GUI Layout Only” on page 7-12 “Displaying a GUI Layout Only” on…
Saving and Displaying Only the GUI Layout 7-13 open('mygui.fig') openfig('mygui') hgload('mygui') You can run a GUI that has no M-file only if you set…
7 Saving and Running the GUI
Callbacks: An Overview (p. 8-2) Introduces the functions, referred to as callbacks, that you use to program GUI behavior. GUI Files: An Overview (p.…
Callbacks: An Overview After you have laid out your GUI, you need to program its behavior. The code you write controls how the GUI responds to events…
Callbacks: An Overview 8-3 Each kind of callback has a triggering mechanism or event that causes it to be called. The following table lists the…
Note User interface controls include push buttons, sliders, radio buttons, check boxes, editable text boxes, static text boxes, list boxes, and toggle…
GUI Files: An Overview 8-5 GUI Files: An Overview “M-Files and FIG-Files” on page 8-5 “GUI M-File Structure” on page 8-6 “Adding Callback Templates to…
GUI M-File Structure The GUI M-file that GUIDE generates is a function file. The name of the main function is the same as the name of the M-file. For…
GUI Files: An Overview 8-7 Adding Callback Templates to an Existing GUI M-File When you save the GUI, GUIDE automatically adds templates for some…
Associating Callbacks with Components A GUI can have many components and GUIDE provides a way of specifying which callback should run in response to a…
Associating Callbacks with Components 8-9 - When you save the GUI, GUIDE constructs the name of the callback by appending an underscore ( _) and the…
See “Input Arguments” on page 8-13 for information about the callback input arguments. When you save the GUI, GUIDE also opens the GUI M-file in your…
Callback Syntax and Arguments 8-11 Callback Syntax and Arguments GUIDE defines conventions for callback syntax and arguments and implements these…
When GUIDE generates the template, it creates the callback name by appending an underscore (_) and the name of the callback property to the…
Callback Syntax and Arguments 8-13 References in the M-file to the field of the handles structure that contains the component’s handle. See “The…
handles = figure1: 160.0011 edit1: 9.0020 uipanel1: 8.0017 popupmenu1: 7.0018 pushbutton1: 161.0011 output: 160.0011 GUIDE creates and maintains the…
Initialization Callbacks 8-15 Initialization Callbacks GUIDE automatically includes two callbacks, the opening function and the output function, in…
% Choose default command line output for mygui handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes mygui…
Initialization Callbacks 8-17 handles.output = hObject adds a new element, output, to the handles structure and assigns it the value of the input…
% Get default command line output from handles structure varargout{1} = handles.output; Input Arguments The output function has three input arguments…
Examples: Programming GUI Components 8-19 Examples: Programming GUI Components This section provides basic code examples to get you started…
function pushbutton1_Callback(hObject, eventdata, handles) display Goodbye delete(handles.figure1); Adding an Image to a Push Button or Toggle Button…
Examples: Programming GUI Components 8-21 elseif button_state == get(hObject,'Min') % Toggle button is not pressed-take appropriate action ... end…
function checkbox1_Callback(hObject, eventdata, handles) if (get(hObject,'Value') == get(hObject,'Max')) % Checkbox is checked-take approriate action…
Examples: Programming GUI Components 8-23 Triggering Callback Execution For both UNIX and Windows, clicking inside the GUI but outside the edit text…
function listbox1_Callback(hObject, eventdata, handles) index_selected = get(handles.listbox1,'Value'); list = get(handles.listbox1,'String')…
Examples: Programming GUI Components 8-25 is fixed, then you can use this approach. Else, you can use the index to retrieve the actual string for the…
Note To set Resize behavior for the figure to Other (Use ResizeFcn), select GUI Options from the Layout Editor Tools menu. 1 This example of a…
Examples: Programming GUI Components 8-27 For radio buttons and toggle buttons that are managed by a button group, you must include the code to…
plotting of a graph to an axes. In this case, the button’s Callback callback contains the code that generates the plot. This example plots a graph in…
Examples: Programming GUI Components 8-29 Plotting to a GUI with Multiple Axes If a GUI has multiple axes, explicitly specify which axes you want to…
2 Add this code to the Plot 2 push button’s Callback callback. The contour function displays the contour plot of a matrix, in this case the output of…
Examples: Programming GUI Components 8-31 default). From the Layout Editor select Tools -> GUI Options -> Command Line Accessibility: Callback . See…
2 Activate the GUI by clicking the Run icon on the toolbar and save the GUI when prompted. GUIDE displays the GUI shown in the following figure and…
Examples: Programming GUI Components 8-33 3 View the ActiveX Properties with the Property Inspector. Select the control in the Layout Editor, and then…
If you click the GUI enough times, the circle disappears entirely. Programming a User Interface Control to Update an ActiveX Control This topic…
Examples: Programming GUI Components 8-35 handles.default_radius = handles.activex1.radius; 3 In the activex1_Click callback, reset the slider’s Value…
at the MATLAB prompt. This displays the available methods in a new window, as shown in the following figure. Alternatively, you can enter…
Examples: Programming GUI Components 8-37 Compiling a GUI that Contains an ActiveX Control If you use the MATLAB Compiler mcc command to compile a GUI…
When a user selects the to file option under the Edit menu’s Copy option, only the to file callback is required to perform the action. Suppose…
Examples: Programming GUI Components 8-39 Note From the Menu Editor, you can view a menu item’s Callback callback in your editor by selecting the menu…
8 Programming the GUI
Managing Application-Defined Data Mechanisms for Managing Data (p. 9-2) Describes various mechanisms for managing application-defined data. Explains…
9 Managing Application-Defined Data 9-2 Mechanisms for Managing Data Most GUIs generate or use data that is specific to the application. This topic…
Mechanisms for Managing Data 9-3 GUI data provides application developers with a convenient interface to a figure’s application data: You do not need…
9 Managing Application-Defined Data 9-4 2 Use the following command to save the data. guidata(hObject,handles) where hObject is the handle of the…
Mechanisms for Managing Data 9-5 The following table summarizes the functions that provide access to application data. For more detailed information…
9 Managing Application-Defined Data 9-6 1 Use getappdata to retrieve the structure. From the example in the previous topic, the name of the…
Sharing Data Among a GUI’s Callbacks 9-7 Sharing Data Among a GUI’s Callbacks You can use GUI data, application data, and the UserData property to…
9 Managing Application-Defined Data 9-8 The GUI behavior is as follows: When a user moves the slider, the text box displays the slider’s current…
Sharing Data Among a GUI’s Callbacks 9-9 3 Set the slider value from the edit text Callback callback. The edit text Callback sets the slider’s value…
9 Managing Application-Defined Data 9-10 functions setappdata, getappdata, isappdata, and rmappdata to manage application data. See “Application Data”…
Sharing Data Among a GUI’s Callbacks 9-11 % Retrieve and increment the error count. slider_data = getappdata(handles.figure1,'slider')…
9 Managing Application-Defined Data 9-12 2 Set the edit text value from the slider Callback callback. Add this statement to the slider Callback.…
GUI with Multiple Axes (p. 10-2) Analyze data and generate frequency and time domain plots in the GUI figure. List Box Directory Reader (p. 10-9) List…
GUI with Multiple Axes This example creates a GUI that contains two axes for plotting data. For simplicity, this example obtains data by evaluating an…
GUI with Multiple Axes 10-3 View Completed Layout and Its GUI M-File If you are reading this in the MATLAB Help browser, you can click the following…
To create the default values, set the String property of the edit text. The following figure shows the value set for the time vector. Identifying the…
GUI with Multiple Axes 10-5 For example, the Tag of the axes used to display the FFT is set to frequency_axes. Therefore, within a callback, you…
like you would on the command line. Note that Callback is the default setting for command-line accessibility. See “GUI Options” on page 5-9 for more…
GUI with Multiple Axes 10-7 Making the appropriate axes current using the axes command and the handle of the axes. For example…
plot(t,x) set(handles.time_axes,'XMinorTick','on') grid on
List Box Directory Reader 10-9 List Box Directory Reader This example uses a list box to display the files in a directory. When the user double clicks…
Note The following links execute MATLAB commands and are designed to work within the MATLAB Help browser. If you are reading this online or in PDF…
List Box Directory Reader 10-11 First input argument is not a directory, but is a character string and there is more than one argument — execute the…
% Populate the listbox load_listbox(initial_dir,handles) Loading the List Box This example creates a subfunction to load items into the list box. This…
List Box Directory Reader 10-13 guidata(handles.figure1,handles) set(handles.listbox1,'String',handles.file_names,... 'Value',1)…
If the selection is a file — get the file extension (fileparts) to determine if it is a FIG-file, which is opened with guide. All other file types are…
List Box Directory Reader 10-15 does not take this approach for FIG-files since openfig.m is required by the GUI M-file. See open for more…
Accessing Workspace Variables from a List Box This GUI uses a list box to display workspace variables, which the user can then plot. Techniques Used…
Accessing Workspace Variables from a List Box 10-17 View Completed Layout and Its GUI M-File If you are reading this in the MATLAB Help browser, you…
Enabling Multiple Selection To enable multiple selection in a list box, you must set the Min and Max properties so that Max Min > 1. This requires you…
Accessing Workspace Variables from a List Box 10-19 Callbacks for the Plotting Buttons The callbacks for the plotting buttons call get_var_names to…
A GUI to Set Simulink Model Parameters This example illustrates how to create a GUI that sets the parameters of a Simulink® model. In addition, the…
A GUI to Set Simulink Model Parameters 10-21 all component properties and to understand how the components are assembled to create the GUI. You can…
Running the Simulation Once you have set the gain values, you can run the simulation by clicking the Simulate and store results button. The simulation…
A GUI to Set Simulink Model Parameters 10-23 Determine if the model is open (find_system). Open the block diagram for the model and the subsystem…
Calls model_open to ensure that the Simulink model is open so that simulation parameters can be set. Gets the new slider value. Sets the value of the…
A GUI to Set Simulink Model Parameters 10-25 Here is the callback for the Kf Current value text box. function KfCurrentValue_Callback(hObject…
Here is the Simulate and store results button callback. function SimulateButton_Callback(hObject, eventdata, handles)…
A GUI to Set Simulink Model Parameters 10-27 set(handles.ResultsList,'String',ResultsStr); % Store the new ResultsData handles.ResultsData =…
% Store the new ResultsData guidata(hObject, handles) Plotting the Results Data The GUI Plot button callback creates a plot of the run data and adds a…
A GUI to Set Simulink Model Parameters 10-29 % Get data to plot and generate command string with color % specified legendStr =…
The which command returns the full path to the file when it is on the MATLAB path The web command displays the file in the Help browser. This is the…
A GUI to Set Simulink Model Parameters 10-31 In this case, there is no need for the list box callback to execute, so you should delete it from the GUI…
An Address Book Reader This example shows how to implement a GUI that displays names and phone numbers, which it reads from a MAT-file. Techniques…
An Address Book Reader 10-33 An index pointer that indicates the current name and phone number, which must be updated as the user pages through the…
GUI M-file options selected: Generate callback function prototypes Application allows only one instance to run Calling the GUI You can call the GUI…
An Address Book Reader 10-35 & the second element is a MATLAB file, then load that file elseif (length(varargin) == 2 && ...…
Check_And_Load Code Listing This is the Check_And_Load function. function pass = Check_And_Load(file,handles) % Initialize the variable "pass" to…
An Address Book Reader 10-37 guidata(handles.Address_Book,handles) else errordlg('Not a valid Address Book','Address Book Error') end The Open Menu…
The Contact Name Callback The Contact Name text box displays the name of the address book entry. If you type in a new name and press enter, the…
An Address Book Reader 10-39 set(handles.Contact_Name,'string',Addresses(i).Name) set(handles.Contact_Phone,'string',Addresses(i).Phone) handles.Index…
dialog. Both the current address book and the index pointer are saved in the handles structure so that this data is available to other callbacks. If…
An Address Book Reader 10-41 Determining Which Button Is Clicked The callback defines an additional argument, str, that indicates which button, Prev…
% If the index is less than one then set it equal to the index % of the last element in the Addresses array if i < 1 i = length(Addresses); end case…
An Address Book Reader 10-43 the Contact_Name_Callback or the Contact_Phone_Callback updates handles.Addresses. Saving the MAT-File If the user…
save(File,'Addresses') handles.LastFile = File; guidata(hObject, handles) end end The Create New Menu The Create New menu simply clears the Contact…
An Address Book Reader 10-45 Changing the Width If the new width is greater than the original width, set the figure to the new width. The size of the…
Original_Size = [ 0 0 94 19.230769230769234]; % If the resized figure is smaller than the % original figure size then compensate. if…
Using a Modal Dialog to Confirm an Operation 10-47 Using a Modal Dialog to Confirm an Operation This example illustrates how to use the modal dialog…
Note The following links execute MATLAB commands and are designed to work within the MATLAB Help browser. If you are reading this online or in PDF…
Using a Modal Dialog to Confirm an Operation 10-49 Setting Up the GUI with the Close Button To set up the second GUI with a Close button, do the…
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) 9 After these…
Using a Modal Dialog to Confirm an Operation 10-51 Clicking the Yes button closes both the close dialog and the GUI that calls it. Clicking the No…
Updates the output field in the handles structure Executes uiresume to return control to the opening function where uiwait is called. 5 The output…
Creating GUIs Programmatically This section provides examples of graphical user interfaces (GUIs) created programmatically. Note Following the release…
Functions for Creating GUIs Introduction (p. 11-2) Introduces the topic. Function Summary (p. 11-3) Summarizes MATLAB functions specifically intended…
11 Functions for Creating GUIs 11-2 Introduction MATLAB provides a selection of functions for creating GUIs. Some of these create standard dialog…
Function Summary 11-3 Function Summary “Predefined Dialog Boxes” on page 11-3 “Creating Components” on page 11-3 “ActiveX Controls” on page 11-4…
11 Functions for Creating GUIs 11-4 ActiveX Controls Using Application-Defined Data Interactive User Input Working with Preferences uitoggletool…
Function Summary 11-5 Utilities setpref Set preference uigetpref Open dialog box for retrieving preferences uisetpref Manage preferences used in…
11 Functions for Creating GUIs
Examples of GUIs Created Programmatically Introduction (p. 12-8) Introduces the examples and lists the programming techniques they illustrate. GUI…
Introduction This chapter provides three examples that illustrate the application of certain techniques in programmatically created GUIs. “GUI with…
GUI with Axes, Menu, and Toolbar 12-9 GUI with Axes, Menu, and Toolbar The initial topics introduce the example and the techniques it illustrates…
You can select other plots in the pop-up menu. Clicking the Update button displays the currently selected plot on the axes. The GUI File menu has…
GUI with Axes, Menu, and Toolbar 12-11 Techniques Used in the Example This example illustrates the following techniques: Passing input arguments to…
mOutputArgs = {}; % Variable for storing output when GUI returns mPlotTypes is a 5-by-2 cell array that holds the data to be plotted in the axes. The…
GUI with Axes, Menu, and Toolbar 12-13 The figure function creates the GUI figure. Setting the MenuBar and Toolbar properties to none, prevents the…
Note If you specify the Units property, then the Position property, and any other properties that depend on the value of the Units property, should…
GUI with Axes, Menu, and Toolbar 12-15 The uicontrol function creates various user interface controls based on the value of the Style property. This…
Here, setting the Parent property of the File menu to hMainFigure makes it the child of the main figure. This statement creates a menu bar in the…
GUI with Axes, Menu, and Toolbar 12-17 The uipushtool TooltipString property assigns a tool tip that displays when the GUI user moves the mouse…
Defining the Callbacks This topic defines the callbacks that service the components of the GUI. Because the callback definitions are at a lower level…
GUI with Axes, Menu, and Toolbar 12-19 Note MATLAB automatically passes hUpdateButtonCallback two arguments, hObject and eventdata, because the Update…
Print Menu Item Callback The hPrintMenuitemCallback function services the Print menu item and the Print toolbar button . Selecting the menu item or…
GUI with Axes, Menu, and Toolbar 12-21 if strcmp(selection,'No') return; end delete(hMainFigure); end The hCloseMenuitemCallback function calls the…
Color Palette The color palette example includes these topics: “The Example” on page 12-22 “Techniques Used in the Example” on page 12-25 “View the…
Color Palette 12-23 The Components The colorPalette includes the following components: An array of color cells defined as toggle buttons An Eraser…
Displays the selected color in the preview area. The red, green, and blue values for the newly selected color are displayed in the R, G, and B fields…
Color Palette 12-25 The colorPalette function accepts property value pairs as input arguments. Only the custom property Parent is supported. This…
Note The following link executes MATLAB commands and is designed to work within the MATLAB Help browser. If you are reading this online or in PDF, you…
Color Palette 12-27 Note Three eventdata fields are defined for use with button groups ( uibuttongroup). These fields enable you to determine the…
2 Data creation. Because the example uses nested functions, defining this data at the top level makes the data accessible to all functions without…
Color Palette 12-29 Passing Input Arguments to a GUI Inputs to the GUI are custom property/value pairs. colorPalette allows one such property: Parent.…
2 If it finds a match, processUserInputs assigns the value that was input for the property to its variable in the third column of the mPropertyDefs…
Color Palette 12-31 Just before returning, colorPalette assigns mOutputArgs the function handle for its getSelectedColor helper function and then…
% update color of the selected block mIconCData(y, x,:) = color; localUpdateIconPlot(); end end
Icon Editor 12-33 Icon Editor The icon editor example includes these topics: “The Example” on page 12-33 “Techniques Used in the Example” on page…
The Components The GUI includes the following components: A edit text that instructs the user or contains the name of the file to be edited. The edit…
Icon Editor 12-35 3 Erase the color in some squares. Click the Eraser button on the palette Click in specific squares to erase those squares Click and…
Note The following links execute MATLAB commands and are designed to work within the MATLAB Help browser. If you are reading this online or in PDF…
Icon Editor 12-37 The example also includes the helper functions listed in the following table. M-File Structure The iconEditor is programmed using…
3 GUI figure and component creation. 4 Command line input processing. 5 GUI initialization. 6 Block execution of the program until the GUI user clicks…
Icon Editor 12-39 Returning Only After the User Makes a Choice At the end of the initialization code, and just before returning, iconEditor calls…
Passing Input Arguments to a GUI Inputs to the GUI are custom property/value pairs. iconEdit allows three such properties: IconWidth, IconHeight, and…
Icon Editor 12-41 1 processUserInputs sequences through the inputs, if any, and tries to match each property name to a string in the first column of…
% different platforms prepareLayout(hMainFigure); prepareLayout first uses findall to retrieve the handles of all objects contained in the figure. The…
Icon Editor 12-43 Background Color. The default component background color is the standard system background color on which the GUI is running. This…
Character units are defined by characters from the default system font. The width of a character unit equals the width of the letter x in the system…
Icon Editor 12-45 function color = getSelectedColor % function returns the currently selected color in this % colorPlatte color = mSelectedColor; The…
iconEditor calls prepareLayout with the handle of the main figure, in the initialization section of the M-file. prepareLayout(hMainFigure); First…
Icon Editor 12-47 height of a character unit is the distance between the baselines of two lines of text. Note that character units are not square.
12 Examples of GUIs Created Programmatically
Index-1 Index A ActiveX controls adding to layout 6-22 programming 8-31 aligning components in GUIDE 6-39 Alignment Tool GUIDE 6-39 application data…
Index Index-2 cross-platform compatibility GUI background color 6-64 GUI design 6-63 GUI fonts 6-63 GUI units 6-66 D data sharing among GUI callbacks…
Index Index-3 GUI object hierarchy viewing in GUIDE 6-62 GUI options (GUIDE) function prototypes 5-11 singleton 5-11 system color background 5-11 GUI…
Index Index-4 M-file generated by GUIDE 5-11 moving components in GUIDE 6-34 N naming a GUI in GUIDE 7-2 O Object Browser (GUIDE) 6-62 opening .fig…
Další dokumenty pro Software MATLAB SIMULINK 7 - GRAPHICAL USER INTERFACE
Otázky k MATLAB SIMULINK 7 - GRAPHICAL USER INTERFACE
K tomuto návodu zatím nejsou žádné otázky. Položte první.
Související produkty a manuály pro Software MATLAB SIMULINK 7 - GRAPHICAL USER INTERFACE
- Software MATLAB CONTROL SYSTEM TOOLBOX 9 Uživatelská příručka
(649 stránek) - Software MATLAB FINANCIAL DERIVATIVES TOOLBOX Uživatelský manuál
(119 stránek) - Software MATLAB SIMEVENTS RELEASE NOTES Uživatelská příručka
(114 stránek) - Software MATLAB SIGNAL PROCESSING TOOLBOX 6 Uživatelský manuál
(60 stránek) - Software MATLAB SIMULINK VERIFICATION AND VALIDATION - S Uživatelská příručka
(674 stránek) - Software MATLAB IMAGE PROCESSING TOOLBOX - RELEASE NOTES Uživatelská příručka
(122 stránek) - Software MATLAB SYSTEM IDENTIFICATION TOOLBOX 7 Uživatelská příručka
(531 stránek) - Software MATLAB DATABASE TOOLBOX RELEASE NOTES Uživatelská příručka
(298 stránek) - Software MATLAB DESIGN HDL CODER RELEASE NOTES Uživatelská příručka
(410 stránek) - Software MATLAB POLYSPACE 7 Instalační příručka
(618 stránek) - Software MATLAB PARALLEL COMPUTING TOOLBOX 4 Uživatelská příručka
(128 stránek) - Software MATLAB DATABASE TOOLBOX RELEASE NOTES Uživatelská příručka
(684 stránek) - Software MATLAB REAL-TIME WORKSHOP 7 - TARGET LANGUAGE COMPILER Uživatelský manuál
(408 stránek) - Software MATLAB APPLICATION DEPLOYMENT - WEB EXAMPLE GUIDE Uživatelský manuál
(22 stránek) - Software MATLAB CURVE FITTING TOOLBOX - RELEASE NOTES Uživatelský manuál
(54 stránek) - Software MATLAB GAUGES BLOCKSET RELEASE NOTES Uživatelská příručka
(114 stránek) - Software MATLAB EMBEDDED IDE LINK 4 - FOR USE WITH TEXAS INSTRUMENTS CODE COMPOSER STUDIO Specifikace
(126 stránek) - Software MATLAB SIMULINK 7 - GRAPHICAL USER INTERFACE Specifikace
(216 stránek) - Software MATLAB REAL-TIME WORKSHOP 7 - TARGET LANGUAGE COMPILER Uživatelská příručka
(386 stránek) - Software MATLAB BUILDER EX 1 Uživatelská příručka
(164 stránek)



