0 ratings0% found this document useful (0 votes) 181 views16 pagesMATLAB
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
MATLAB’
Advanced GUI Development
ScoTT 7. sMITH‘Copyright 2006 by Scot T, Smith
All fights Reserved
[No par of this pubiction maybe reproduced, store in aetreval system, we tasted in
any former by any means, electric, mechanical. photocopying. teonling. cr aherwise,
without the-writin pernission of the author
OpenGL © is a tepistered taemark of Silicon Graphies Inc.
Solaris isa registered trademark of Sun Misnasysterns Inc.
Mac-0-X* isa registered tradsmark of Apple Computer Ins.
(MS Windows is a registered trademark of Microsoft Corporation
MATLAM® Handle Griphics®, and GUIDES are registered ridemarks of The
‘MathWorks, Ine. and are used with permission. The Math Works dees not warrant
saracy of the texL or esersises in this book, This book's use or discussion of
MATLAM® sofware or related prexiucts oes not constitule endorsement oF spem-
socship by The Mathborks of a particular pedugogieal approach or particular use of
the MATLAB® software
For MATLAB® and Simmulink® product information, please coma
“The MathWorks, Ine;
3 Apple Hill Drive
Natick, MA, 01762008 USA
“Fel: SOe-67- 7000
Fag S08-147-700),
E-mail: infocamathvors.com
Web: svavmathivarks com
First published by Dog Ear Publishing
4010 W. 8th Street, Ste HE
Indianapolis, IN 46268
swslossarablsins st
do;
SOR ears
ISBN: 1-59R58-1813
‘This book is printed on acid-free paper.
Printed in che United States oF AmerienTable of Contents
Chapter
introduction.
41.1 Why Develop GUIs Using MATLAB?
4.1.4 High-Level Script Based Development.
4.1.2 Seamless Integration with Existing MATLAB Computational
Power 2
41.1.3. Operating System Independent GUI Applications
4.1.4 User interactivity and Real-time Measurements.
1.2 MATLAB Capabilities For GUI Development
1.24 Handle Graphics Objects... -
1.2.2 Figures, Axes, and UIControls..
1:23 GUIDE, Graphical User Interface Development Environment
4.2.4 Event Handling: Callback Functions, Timers, and
Mousa’Keyboard Input .
1.25 Global Variables...
1.28 Stand-alone Executable GUIs
4.3. Where To Download N-files..
Chapter
2.1 Introduction To Handle Graphics Objects
2.41.1 HG Object Hierarchy ... oe
2.12 The Root Object.
2.2 Handle Graphics Objects and Propertic:
2.2.1 Retrieving and Storing Properties Using set ) and gett)...
2.22 Common HG Object Properties .
2.3. Figure Object Propertie:
2.3.1 Figute PrOPETHES wer onnn
2.3.2 Settings
2.3.3. Callback Functions,
2.4 Axes Propertie:
2.4.1 Axes Object Settings ..
2.4.1.1 Anes Propertios For 20 Plot Applications...
24.1.2 Axes Properties For 30 Plot Appications...
24.1.3 Axes Proportieg For imagng Anpleabans.o.....
2.4.2 Axes Object Callback Functions. a
2.5 Axes Child Object Properties
2.5.1 Gore Objects...
2511 dinage Objects
B12 LGD O[B6I8.c0.0s 0 oon“I
25.1.3 Line Opjects
25.14 Patath O/8688 v0.0 on
2.54.8 Rectangle Ob/eCt8 0.
25.1.6 Surface Objects.
2517 Text Objects
252° Plot Objects...
2.5.3 Group Objects.
254 Annotation Objects...
2.6 UI Object Properties.
2.6.4. UlControls
26.1.4 Check Boxes.
26.1.2 Regio Buttons
261.3 Edit Text Boxes
26.14 Static Text Labels.
26.15 List Boxes.
26.1.6 Push Buttons.
26.1.7 Toggle Buttons...
2618 Siders
26.1.9. Popup Menus
26.2 UIMenu..
2.6.3 UlContextMenu
2.6.4 UIButtonGraup
265 UIPanel
26.6 UlTeolbar, UlPushTaol, and UlTaggleTaal
Chapter 3: MATLAB GUIDE: GUI
Development Environment.
3.1 Introduction To GUIDE, Graphical User Interface
Development Environment 137
3.1.1 Advantages of Using GUIDE... 138
3.4.2. Gelting Started With GUIDE... 38
3.2 GUIDE Options and Setup. 142
3.21 GUI Options seen a 143,
3.2.2. Grids and Rulers. 146
323. GUI Figure Size... 146
3.3. Property Inspector and Object Browser ..
3.2.1 Property Inspector
3.3.2 Object Browser.
3.4 Generating Callback Functions
34.1 Callback Naming CoAVENtIONS ..... nes nesen nnn 150
3.5 Greating User Interface Menus
3.5.1 Menu Bars. us -
3.5.2 Context Menus o os oevu
3.6 Automatic M-file Code Generation and Structure
157
3.6.1 Auto-generated M-file Structure:
3.6.2. Main Function
3.6.3 Main Function Initialization ...
3.6.4 Renaming GUI Projects........
3.6.5 Removing GUI Objects and Associated Callback Functions 160
Chapter
Structure of MATLAB GUIs......164
4.1 GUI Design Sty!
Layout, and Program Flow. 161
4.1.1 Defining The GUI... 161
4.12 GUI Design Styles and Layout 162
4.1.3. Program Flow... os 182
4.1.4 Example of Defining A GUI: FigView.... sonnei 168
4.2 Handles Data Structure Organization. 165
4.2.1 Handles Data Structures... 185
4.2.2 Initializing GUI Properties and Variables 168
4.23 Handles and Callback Funct
4.24 Limitations of Handles ...
4.3 Event Handling
4.3.4 The Event Queue. onsen
4.32 Mouse Events... ne 182
433. Key Press Events.......
4.34 Timer Events
4.4 Dialog Boxes,
44.1 MATLAB Buittin Dialog Boxes...
44.2 Custom Dialog Boxes... esa
Examples...
Chapter
Advanced GUI Designs.
5.1 Multiple Figure GUIs...
5.1.1. Global Variables
5.1.2 Interactive Multiple Control GUIs, .
5.1.3 EquationAnimator: Multiple Figure GUI Design Example... 233
5.2 Real-time GUIs and Animation ...
5.2.1. Using Timers For Loops ssnssnnsate BAT
5.22 Animating HG Objects
5.2.3 Realtime Controls.
5.3 Custom GUI Control Styles...
5.3.1. Image Mapped Controls, IMCs...
§.3.2 Image Mapped GUI Layouts.
5.33. IMC Callbacksvin
5.3.4 Highlighting IMGs Based On Mouse Pointer... 282
5.4 Creating Stand-Alone Executable GUISs.. 292
5.4.1 Requirements and Limitations. sna nn B92
5.4.2 Nefile Only Executable Generation... severe BB
5.4.3 Command Window. son 208
5.4.4 Deploying Your GUI Application ..s.enssesnenmnvnenn inn 2M€xercises
Exercise 2.1: HG Object Manipulation Using set() and geti)..
Exercise 2.2: Using The Parent Property To Control Graphie Objects... 19
Exercise 2. 28
}: Creating Custom Figures Using Properties
Exercise 2.4:
Properties For 2D Graphics Applications. 35
Exercise 2.5: Axes Properties For 3D Plat Applications ..
Exercise 2.6: Axes Properties F hotos and Video.
Exercise 2.7: Using Text Objects As In
ractive Control
Exercise 2.8: UIManu Programming.
Exercise 2,9: Using UIToolbars.
Exorcise 3.1: Creating A GUI Projoct..
Exercise 3.2: Property Inspector and Object Brow:
ToO16
Exercise 3.
Callback Function Naming Using The Tag Property
Exercise 3.4: Creating Menu Bars and Context Menus.
Exercise 4.1: Fig View Layout and Handles Structure Creation
Exercise 4.2: Mouse Event Programming, FigView ....
Exercise 4.3: Dialog Bomestsssnnesin
Exercise 5.1: GHS Architecture Far EquationAnimator,
Exercise 5.
Implomenting EquationAnimator.€xamples
Example 2-4: Patch Objects
Example 2.2: Rectangle Objects.
Example 2.3: Plot Objects.
Example 2.4: Check Box Programmin;
Example 2.5: Switeh Yard Meth
Example 2.6: Separate Callbacks Method Fer Radio Buttons.
Example 2.7: Edit Text Box Sing!
nd Multiple Line inputs.
Example 2.8: Static Text Labo!
Example 2.9: Multiple Input List Box
Example 2.40: List Box Control Using Cell Arrays...
Example 2.11: Push Button Controls son
Example 2.12: Pushbuttons With Graphical Icons Using CData
Example 2.13: Toggle Buttons
Example 2.1
lider Controls.
Example 2.15: Popup Menus .
Example 2.16: Context Menus..j.nssinssniitnitsnniensaniesnenanine WEB
Example 2.47: UlButtonGroup Objects suse
Example 2.18: UlPane! Object Group Manipulation.
Example 4.1: Example of Defining A GUI: Figview
se 128
Example 4.2: Event Processing.
Example 4.3: Key Press Event Processing
Example 4.5: Custom Dialog GUI
Example 5.1: Equation Animator: Multiple Figure GUI Design.
Example 5.2: Animation of Plat Dat
Example 5.3: Real-time Stider Central
Example 5.4: Image Mappod Controls, IMCs.
Example 5.5: Image Mappod Controls: AVI Vidoo Player ror
Example 5.6: Compiling Stand-alone Executable:xi
Figures
Figure 4.4 - EquationAnimator multiple figure GUI example.
Figure 4.2 - Example GUI showing Figure, Axes, UIControl, and D1
Box Figure Objects
Figure 1.3 - Example high-tevel GUI layout using GUIDE
Figure 2.1 - HG Object Hierareny .
Figure 2.2 - WG Object hierarchy browsing using MATLAB Help "
Figure 2.3 - Using the sor// function to alter Figure Color and Colormap
Properties nn 2a
Figure 2.4 - Exercise 2.3 graphics output gure on 29
Figure 2.5 - Exercise 2.4 output figur aw
Figure 2.6 Exercise 2.5 output view 4
Figure 2.7 - Exercise 2.5 output view 2 42
Figure 2.8 - Exercise 2.5 output view 3 42
Figure 2.9 - Exercise 2.6 output, setting on Axes for images. ar
Figure 2.10 - Image output Axes resulting from Amage/) function call 48
Figure 2.11 » Setting an Axes for image data analysis.
sesaesecee 4
Figure 2.12 - Using XData and YData Axes properties for image scaling
82
Figure 2.13 « Mulitple line objects using Jime() function 53
Figure 2.14 - Example:2.4 output, Patch Objects 37
Figure 2.15 - Example 2.2 output, Rectangle Objects 59
Figure 2.16 - Exercise 2.7 output, Text Objects as interactive Controis.66
Figure 2.17 - Example-2.3 output, Plot Objects 69
Figure 2.18 - Example of using makehgtform() to transform Group
objects. 13
Figure 2.19 - Example of Annotation Obj 75
Figure 2.20 - Example 2.4 output, Chock Box UICOREIO! OFF vecrerinernn 84
Figure 2.21 - Example 2.4 output, Chock Box UICONtI! 70M penrerimernn 84
Figure 2.22 - Example 2.5 output, Radiebutton switeh yard pregrammingx
Figure 2.23 - Example 2.7 output, Edit Text Boxes...
Figure 2.24: Example 2.8 owtput, Static Text Labels
Figure 2.25: Example 2.9 output, multiple input List Box...
Figure 2.26: Example 2.9 output, plot figure sence seuss ses OF
Figure 2.27: Example 2.44 output, Pushbutton control:
Figure 2.26: Example 2.41 output, plot data...
‘xample 2.42 output, Pushbuttons with graphical icons . 104
‘xample 2.13, togglebuttons stop and pause grayed-out. 107
:xample 2.13, togglebutton play
gure 2.36; Exercise 2.8 output, UIMens programm
Figuro 2.37; Example 2.16 output, UlContextMene for Axes.
xample 2.16 output, UIContentMent for FIGUTE sn
xample 2.17 output, UIButtonGroup exam
Figure 2.31
utput, WIToolbar object not selected.
utput, UIToolbar object selected
jon tool
Starting GUIDE from MATLAB
Figure 3.2: GUIDE Quick Start window
Figure 3.3: Context menu for MATLAB toolbar .
Figure 3.4: Shortcut Editor a...
Figure 3.5: Shortcut added to toolbar oe...
Figure 3.6: GUIDE Preferences window.
Figure 3.7: GUIDE with component names enabled
Figure 3.8: GUI Options window in GUIDE...
Figure 3.9: Grids and Rulers setup window.
xercise 3.2 GUIDE layout
xercise 3.3 output, Main GUI running from GUIDE..
: Menu Editor window..Figure 3.13: Assigning a context menu using Property Inspector
Figure 3.14: Exercise 3.4 menu editar example wus
Figure 3.15: Exercise 3.4, Main GUI example with Menus added..
Figure 4.1: Example 4.1 conceptual drawing of FigView GUI layaut.... 164
Figure 4.2: Handles data structure hierarchy for FigView .....
Figure 4.3: FigView layout.
167
Figure 4.4: FigView running after functional programming.
Figure 4.5: MATLAB event queue and processing dia
Figure 4.6: Exercise 4.2 output, zoom capabilities
Figas
Open File default disiog box
Figure 4.8: Error dialog box...
Figure 4.9: Question ai
1g box, 3 buttons.
Figure 4.10: Question dialog box, 2 buttons .
Figure 4.14: Input to»
iatog bos
Figure 4.12: List box dialog .
Figure 4.13: Font selector dial
Figure 4.14: Directory selector dialog box.
Figure 4.45: Open file
Figure
Foctor dialog box..
.16: Exercise 4.3, Open File selector di
Figure 4.17: Exercise 4.3, Question dialog added to Figview.
Figure
14: Default Modal Dialog Box in GUIDE.
Figure 4.19: Example 4.5 output, custom plot selector dialog box
Figure 5.1: Conceptual drawing of a multiple figure GUI jacisucsnsueni 226
Figure 5.2: Parameter passing between GUI figure:
Figure 5.3: Global Handle Sharing architecture for multifigure GUI:
Figure 5.4: oa main-fig in GUIDE.
Figure 5.5: ea graphics.flg in GUIDE.
Figure 5.6: ea controls.fig in GUIDE
sn for EquationAnimator.
Global Variable Structure for EquationAnimator
240xIV
Figure 5.9: Timer event processitijeun
Figure 5,
: Sereenshat of ea main running,
Figure 5.11: Sereenshet ea graphics running...
Figure 5.42: Screenshot of ea controls running ssc
Figure 5.43: Example GUI with image mapped controls
Figure 5.4
Figure 5.1
Example 5.5 layout in GUIDE, image mapped controls... 284
288
stand-alone executable Gommand Window.Accelerator
UIMenu = 116
Animate - 116
animated control buttons - 199
Animating HG Objects » 242
jimation * 241
tion Loops + 199
Animation of Plot Data» 243
audio 9
auto-generated M-file code - 157
AVI Video Player - 283
avlinfig) * 283
savirecd) - 283
Axes Child Object:
Axes Objects 30
AmbientLightColor 37
Box 34
‘CameraPasition - 37
‘CameraPositionMode -37
‘CameraTarget : 37
‘CameraTargetMode «37
‘CameraUpVeetor - 37
‘CameraUpVectorMode » 37
‘CameraViewAngle » 37
CameraViewAngleMade «38
‘Color - 34
‘ColorOrder -34
FontAngle 34
FontName: 34
FontSize - 34
Fouteight -34
GridLineStyle » 34
LineStyleOrder - 34
50
NextPlot - 34.
299
Index
OuterPosition : 34
Position 34
Projection « 38
TickDir «34
TickLength 34
Title - 34
XColor 34
NGrid 34
Label 34
YColor «34
YGrid 34
YLabel 34
Zalor 38
ZGrid 38
ZMinorGrid » 38
Axes Properties “30
Aais Rotation - 71
B
BusyAction - 179
c
callback fisnctions 20
Callback Functions
event dasa + 27
Callback Func
wurce ~ 27
camera properties + 38,
Check Boxes - 78
Value - 83
Cheeked
UlMenu > 116
CloseReqeustFeng) 23
color image: $1300
colormap() + 25
‘Common HG Object Properties
ButtonDownFen : 19
Children «19
CreateFen - 19
DeleteFen 19
Parent 19
Tag - 19
Visible «19
Context Menus: J53
custom controls - 279
(Custom Dialog Boxes «215
D
Design Style - 162
Dialog Boxes - 202
Passing Arguments» 216
uigerfilet) 202
digital photograph «43
displaying images + 44
double click + 183
etravrnave 39, 179, 180
dynamic plats » $4
dynamic UtCantrols - 199
E
Edit Text Boxes: 78,90
multiple line inputs 90
-strddoubled) « 92
Ervordlig- 205
eval) ~ 98
Event Handling * 7
event queue + 178, 242
events - 178
executable «See stand-alone
executable
F
igure“ 180
Figure Objects - 20
Figure Properties + 20
Color 23
ColorMay
CurrentPoint 25
CurrentPoint - 25
MenuBar - 25, 26
Name 25
NumberTitle + 25
25
terShapeCData : 25
PointerShapeHotSpot - 25
Position - 25
Resize -26
ToolBar» 25,26
WindowButtonMotionFen -
idawStyle 25
File Dialogs - 209
file-browsing 202
Fourier series $4
G
ger() Function - 14
getframe 18
GH methodology + 233
Global Handle Sharing, Gi
231
global variables
potential pitfalls - 227
Global Variables - 8, 225
Graphical Layout 163
Group Objects - 69
GUL Interaction Diagrams -
29
guri_mainfen - 189
‘gui_State~ 159
‘guidertay) - V6
GUIDE - 6
Callback Functions + 150‘component palette : 143
features + 137
preferences « 142
Resize Behav
starting - 139
guhandlest) * 166
ier)
F
Handle Graphies 5,9
Handle Graphies Objects See
Handle Grap!
dances * 16S
fandtes.user * 168
help « 208
HG Object Hierarchy - 10
HG Objects See Handle
Graphies
Hggroup °69
‘Hggroup Objects 70
haggroup()- 70
Hgtransform - 70
Hgtransform Objects - 70
agiramsform() «70
high-level GUI - See GUIDE
Highlighting IMCs - 282
illumination: See Light Objects
image 43
imread() 44
scaling «44
zooming - 44
Image Mapped Control
279
Image Object - 43
Image Objects » 50
ButtonDownFe: 281
image output display “43
Image Properties
AlphaData - 50
AlphaDataMApping - 50
IMCs
301
Data +50
XData -50
YData +50
image() 44
imaging 43
Imaging applications - 43
IMC layouts 281
fnnread) 102
initialiae GUI properties 168
put Dialogs - 207
Inpatdig = 207
interactive controls “61, 241
Interruptible: 179
191
isempiy() 193
keystroke combinations * 191
Key Stroke Codes : 192
KeyPressFen(}: 23, 190
L
LaTeX : 61
Light Objects - 52
Limitations of Handles - 177
Line Objects - 52
Line Properties
LineStyle 53
LineWidth : 53
ker + 53
MarkerEdgeWidth : $3
MarkerFaceColor - 53
MarkerSize - 33
XData “53
YData :53
Fine() 53
List Boxes - 78, 94
cell array of strings - 97
cellsir(y 98
multiple line: 94302
Value + 94,
Listellg - 207
ListString : 207
lowelevel - 77
low-level graphies 54
M
makehgiform@ «7
MATLAB Compiler » 292
‘mee conimand - 293
Menu Bat J
Menu bars - 11S
Menu Editor - 152
Mefile Only Executable » 293
Modal Dialog Box - 215
monochrome image «51
mouse button down events + 183
mouse events
zooming * 185
Mouse Events « 182
alt’ 183
‘CurrentPaint - 182
‘extend! + 183
“normal - 183
“apen! 183,
WindowBuawnMotlonFen()«
182
mogéone 208
multi-figure GUIs 229
Multiple Figure GUIs - 225
N
naming convention - /50
0
Object Browser» L48
object-oriented - 1, 5,9
OpeningFeng) » 168
P
pagesetupdlg* 208
parent-child 9, 1!
sing handles to callback « 170
Patch Objects - 54
Patch Properties
PaceColar- 55
pause: 180
peaks()- 24
periodi¢ event calls * 241
Plat Functions
area) 67
arg) 67
contour() 67
cantour3() “67
caniteniret) ~ 67
contonrfth 67
contourstice() - 67
errorbar) 67
Hine) 67
loglogg(}- 67
mesh) - 67
meshe() - 67
plot) 61
plors > 67
‘plotmatrix() 67
iplotyy() 67
quiver?) 67
guiiver30) 67
scatter() - 67
seatter3Q 67
semilogyd)- 67
semilogyt) - 67
stairsé)° 67
stem(}* 67
stem) “67
sebplott) + 67
seorft) 67
sterfacet) - 67
serfet) 6T
serfl() 67
retramesh() -6T
rimesh() * 67