资源说明:这是一本系统学习matlabGUI编程的好书,你用了之后就知道了,下面是它的目录:
1
What Is a GUI? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
How Does a GUI Work? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4
Where Do I Start? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6
Ways to Build MATLAB GUIs . . . . . . . . . . . . . . . . . . . . . . . 1-8
Creating a Simple GUI with GUIDE
2
GUIDE: A Brief Introduction . . . . . . . . . . . . . . . . . . . . . . . 2-2
What Is GUIDE? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Opening GUIDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Laying Out a GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-7
Programming a GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8
Example: Simple GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-9
Simple GUI Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-9
View Completed Layout and Its GUI M-File . . . . . . . . . . . . 2-10
Laying Out a Simple GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11
Opening a New GUI in the Layout Editor . . . . . . . . . . . . . . 2-11
Setting the GUI Figure Size . . . . . . . . . . . . . . . . . . . . . . . . . 2-14
Adding the Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-15
Aligning the Components . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16
Adding Text to the Components . . . . . . . . . . . . . . . . . . . . . . 2-18
v
Completed Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-23
Saving the GUI Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-25
Programming a Simple GUI . . . . . . . . . . . . . . . . . . . . . . . . 2-28
Adding Code to the M-file . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-28
Generating Data to Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-28
Programming the Pop-Up Menu . . . . . . . . . . . . . . . . . . . . . 2-31
Programming the Push Buttons . . . . . . . . . . . . . . . . . . . . . . 2-33
Running the GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-36
Creating a Simple GUI Programmatically
3
Example: Simple GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2
Simple GUI Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2
View Completed Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3
Function Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4
Creating a GUI M-File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5
Laying Out a Simple GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7
Creating the Figure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7
Adding the Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7
Initializing the GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-11
Programming the GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-14
Programming the Pop-Up Menu . . . . . . . . . . . . . . . . . . . . . 3-14
Programming the Push Buttons . . . . . . . . . . . . . . . . . . . . . . 3-15
Associating Callbacks with Their Components . . . . . . . . . . 3-15
Running the Final GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-17
Final M-File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-17
vi Contents
Running the GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20
Creating GUIs with GUIDE
What Is GUIDE?
4
GUIDE: Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
GUI Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
GUI Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
GUIDE Tools Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3
GUIDE Preferences and Options
5
GUIDE Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
Setting Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
Confirmation Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
Backward Compatibility Preference . . . . . . . . . . . . . . . . . . 5-4
All Other Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6
GUI Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-9
The GUI Options Dialog Box . . . . . . . . . . . . . . . . . . . . . . . . 5-9
Resize Behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-10
Command-Line Accessibility . . . . . . . . . . . . . . . . . . . . . . . . 5-10
Generate FIG-File and M-File . . . . . . . . . . . . . . . . . . . . . . . 5-11
Generate FIG-File Only . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-14
vii
Laying Out a GUIDE GUI
6
Designing a GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2
Starting GUIDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4
Selecting a GUI Template . . . . . . . . . . . . . . . . . . . . . . . . . . 6-6
Accessing the Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-6
Template Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-7
Setting the GUI Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-15
Maximizing the Layout Area . . . . . . . . . . . . . . . . . . . . . . . . 6-18
Adding Components to the GUI . . . . . . . . . . . . . . . . . . . . . 6-19
Available Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-20
A Working GUI with Many Components . . . . . . . . . . . . . . . 6-24
Adding Components to the GUIDE Layout Area . . . . . . . . 6-31
Defining User Interface Controls . . . . . . . . . . . . . . . . . . . . . 6-38
Defining Panels and Button Groups . . . . . . . . . . . . . . . . . . 6-55
Defining Axes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-61
Defining Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-65
Adding ActiveX Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-76
Working with Components in the Layout Area . . . . . . . . . . 6-79
Locating and Moving Components . . . . . . . . . . . . . . . . . . . . 6-82
Resizing Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-85
Aligning Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-88
Alignment Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-88
Property Inspector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-91
Grid and Rulers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-95
Guide Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-95
Setting Tab Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-97
Creating Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-100
Menus for the Menu Bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-102
Context Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-113
viii Contents
Creating Toolbars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-121
Creating Toolbars with GUIDE . . . . . . . . . . . . . . . . . . . . . . 6-121
Editing Tool Icons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-130
Viewing the Object Hierarchy . . . . . . . . . . . . . . . . . . . . . . 6-135
Designing for Cross-Platform Compatibility . . . . . . . . . 6-136
Default System Font . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-136
Standard Background Color . . . . . . . . . . . . . . . . . . . . . . . . . 6-137
Cross-Platform Compatible Units . . . . . . . . . . . . . . . . . . . . 6-138
Saving and Running a GUIDE GUI
7
Naming a GUI and Its Files . . . . . . . . . . . . . . . . . . . . . . . . . 7-2
The GUI Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2
File and GUI Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3
Renaming GUIs and GUI Files . . . . . . . . . . . . . . . . . . . . . . 7-3
Saving a GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-4
Ways to Save a GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-4
Saving a New GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-5
Saving an Existing GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-8
Running a GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-10
Executing the M-file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-10
From the GUIDE Layout Editor . . . . . . . . . . . . . . . . . . . . . 7-10
From the Command Line . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-11
From an M-file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-11
Programming a GUIDE GUI
8
Callbacks: An Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2
Programming GUIs Created Using GUIDE . . . . . . . . . . . . 8-2
ix
What Is a Callback? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2
Kinds of Callbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2
GUI Files: An Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-7
M-Files and FIG-Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-7
GUI M-File Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-8
Adding Callback Templates to an Existing GUI M-File . . . 8-9
About GUIDE-Generated Callbacks . . . . . . . . . . . . . . . . . . 8-9
Associating Callbacks with Components . . . . . . . . . . . . . 8-11
GUI Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-11
Setting Callback Properties Automatically . . . . . . . . . . . . . 8-11
Deleting Callbacks from a GUI M-File . . . . . . . . . . . . . . . . 8-14
Callback Syntax and Arguments . . . . . . . . . . . . . . . . . . . . 8-15
Callback Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-15
Naming of Callback Functions . . . . . . . . . . . . . . . . . . . . . . . 8-16
Changing Callbacks Assigned by GUIDE . . . . . . . . . . . . . . 8-20
Input Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-21
Initialization Callbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-25
Opening Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-25
Output Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-28
Examples: Programming GUIDE GUI Components . . . 8-30
Push Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-30
Toggle Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-32
Radio Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-32
Check Box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-33
Edit Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-34
Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-35
Slider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-36
List Box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-36
Pop-Up Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-37
Panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-39
Button Group . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-42
Axes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-44
ActiveX Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-48
Menu Item . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-58
x Contents
Managing and Sharing Application Data in
GUIDE
9
Mechanisms for Managing Data . . . . . . . . . . . . . . . . . . . . . 9-2
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-2
Nested Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-4
UserData Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-5
Application Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-5
GUI Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-7
Examples of Sharing Data Among a GUI’s Callbacks . . . . 9-10
Making Multiple GUIs Work Together . . . . . . . . . . . . . . . 9-21
Data-Sharing Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-21
Example — Manipulating a Modal Dialog Box for User
Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-22
Example — Individual GUIDE GUIs Cooperating as Icon
Manipulation Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-30
Examples of GUIDE GUIs
10
GUI with Multiple Axes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2
About the Multiple Axes Example . . . . . . . . . . . . . . . . . . . . 10-2
View and Run the Multiple Axes GUI . . . . . . . . . . . . . . . . . 10-3
Designing the GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-4
Plot Push Button Callback . . . . . . . . . . . . . . . . . . . . . . . . . . 10-8
Validating User Input as Numbers . . . . . . . . . . . . . . . . . . . 10-11
GUI for Animating a 3-D View . . . . . . . . . . . . . . . . . . . . . . 10-15
About the 3-D Animation Example . . . . . . . . . . . . . . . . . . . 10-15
View and Run the 3-D Globe GUI . . . . . . . . . . . . . . . . . . . . 10-16
Designing the GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-17
Graphics Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-24
Further Graphic Explorations . . . . . . . . . . . . . . . . . . . . . . . 10-29
GUI to Interactively Explore Data in a Table . . . . . . . . . 10-31
About the tablestat Example . . . . . . . . . . . . . . . . . . . . . . . . 10-31
xi
View and Run the tablestat GUI . . . . . . . . . . . . . . . . . . . . . 10-33
Designing the GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-35
Extending Tablestat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-52
List Box Directory Reader . . . . . . . . . . . . . . . . . . . . . . . . . . 10-54
About the List Box Directory Example . . . . . . . . . . . . . . . . 10-54
View and Run the List Box Directory GUI . . . . . . . . . . . . . 10-55
Implementing the List Box Directory GUI . . . . . . . . . . . . . 10-56
Accessing Workspace Variables from a List Box . . . . . . 10-61
About the Workspace Variable Example . . . . . . . . . . . . . . . 10-61
View and Run the Workspace Variable GUI . . . . . . . . . . . . 10-62
Reading Workspace Variables . . . . . . . . . . . . . . . . . . . . . . . 10-63
Reading the Selections from the List Box . . . . . . . . . . . . . . 10-64
A GUI to Set Simulink Model Parameters . . . . . . . . . . . . 10-66
About the Simulink Model Parameters Example . . . . . . . . 10-66
View and Run the Simulink Parameters GUI . . . . . . . . . . . 10-67
How to Use the Simulink Parameters GUI . . . . . . . . . . . . . 10-68
Running the GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-70
Programming the Slider and Edit Text Components . . . . . 10-71
Running the Simulation from the GUI . . . . . . . . . . . . . . . . 10-73
Removing Results from the List Box . . . . . . . . . . . . . . . . . . 10-75
Plotting the Results Data . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-76
The GUI Help Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-78
Closing the GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-78
The List Box Callback and Create Function . . . . . . . . . . . . 10-79
An Address Book Reader . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-81
About the Address Book Reader Example . . . . . . . . . . . . . . 10-81
View and Run the Address Book Reader GUI . . . . . . . . . . . 10-82
Running the GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-83
Loading an Address Book Into the Reader . . . . . . . . . . . . . 10-85
The Contact Name Callback . . . . . . . . . . . . . . . . . . . . . . . . . 10-88
The Contact Phone Number Callback . . . . . . . . . . . . . . . . . 10-90
Paging Through the Address Book — Prev/Next . . . . . . . . 10-91
Saving Changes to the Address Book from the Menu . . . . . 10-93
The Create NewMenu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-94
The Address Book Resize Function . . . . . . . . . . . . . . . . . . . 10-95
Using a Modal Dialog Box to Confirm an Operation . . . 10-98
About the Modal Dialog Example . . . . . . . . . . . . . . . . . . . . 10-98
xii Contents
View and Run the Modal Dialog Box GUIs . . . . . . . . . . . . . 10-99
Setting Up the Close Confirmation Dialog . . . . . . . . . . . . . 10-100
Setting Up the GUI with the Close Button . . . . . . . . . . . . . 10-101
Running the Close-Confirmation GUI . . . . . . . . . . . . . . . . . 10-102
How the Close-Confirmation GUIs Work . . . . . . . . . . . . . . 10-103
Creating GUIs Programmatically
Laying Out a GUI
11
Designing a GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-2
Creating and Running the GUI M-File . . . . . . . . . . . . . . . 11-4
File Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-4
File Template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-4
Running the GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-5
Creating the GUI Figure . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-7
Adding Components to the GUI . . . . . . . . . . . . . . . . . . . . . 11-10
Available Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-10
Adding User Interface Controls . . . . . . . . . . . . . . . . . . . . . . 11-13
Adding Panels and Button Groups . . . . . . . . . . . . . . . . . . . . 11-32
Adding Axes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-38
Adding ActiveX Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-41
Composing and Coding GUIs with Interactive Tools . . 11-42
Setting Positions of Components Interactively . . . . . . . . . . 11-43
Aligning Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-52
Setting Colors Interactively . . . . . . . . . . . . . . . . . . . . . . . . . 11-58
Setting Font Characteristics Interactively . . . . . . . . . . . . . 11-60
Generating Code to Set Component Properties . . . . . . . . . . 11-62
Summary of GUI Development Tools . . . . . . . . . . . . . . . . . 11-67
Setting Tab Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-68
How Tabbing Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-68
Default Tab Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-68
xiii
Changing the Tab Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-71
Creating Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-73
Adding Menu Bar Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-73
Adding Context Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-79
Creating Toolbars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-86
Using the uitoolbar Function . . . . . . . . . . . . . . . . . . . . . . . . 11-86
Commonly Used Properties . . . . . . . . . . . . . . . . . . . . . . . . . 11-86
Toolbars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-87
Displaying and Modifying the Standard Toolbar . . . . . . . . 11-90
Designing for Cross-Platform Compatibility . . . . . . . . . 11-92
Default System Font . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-92
Standard Background Color . . . . . . . . . . . . . . . . . . . . . . . . . 11-93
Cross-Platform Compatible Units . . . . . . . . . . . . . . . . . . . . 11-94
Programming the GUI
12
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-2
Initializing the GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-4
Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-5
Callbacks: An Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-9
What Is a Callback? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-9
Kinds of Callbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-10
Providing Callbacks for Components . . . . . . . . . . . . . . . . . . 12-13
Examples: Programming GUI Components . . . . . . . . . . . 12-22
Programming User Interface Controls . . . . . . . . . . . . . . . . . 12-22
Programming Panels and Button Groups . . . . . . . . . . . . . . 12-30
Programming Axes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-33
Programming ActiveX Controls . . . . . . . . . . . . . . . . . . . . . . 12-36
Programming Menu Items . . . . . . . . . . . . . . . . . . . . . . . . . . 12-36
Programming Toolbar Tools . . . . . . . . . . . . . . . . . . . . . . . . . 12-39
xiv Contents
Managing Application-Defined Data
13
Mechanisms for Managing Data . . . . . . . . . . . . . . . . . . . . . 13-2
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-2
Nested Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-4
UserData Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-5
Application Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-6
GUI Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-8
Sharing Data Among a GUI’s Callbacks . . . . . . . . . . . . . . 13-11
Sharing Data with Nested Functions . . . . . . . . . . . . . . . . . 13-11
Sharing Data with UserData . . . . . . . . . . . . . . . . . . . . . . . . 13-15
Sharing Data with Application Data . . . . . . . . . . . . . . . . . . 13-18
Sharing Data with GUI Data . . . . . . . . . . . . . . . . . . . . . . . . 13-21
Managing Callback Execution
14
Callback Interruption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-2
Callback Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-2
How the Interruptible Property Works . . . . . . . . . . . . . . . . 14-2
How the Busy Action Property Works . . . . . . . . . . . . . . . . . 14-4
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-4
Examples of GUIs Created Programmatically
15
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-2
GUI with Axes, Menu, and Toolbar . . . . . . . . . . . . . . . . . . 15-3
About the Axes, Menu, and Toolbar Example . . . . . . . . . . . 15-3
Viewing and Running the AxesMenuToolbar GUI
M-Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-5
Generating the Graphing Commands and Data . . . . . . . . . 15-6
xv
Creating the GUI and Its Components . . . . . . . . . . . . . . . . 15-7
Initializing the GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-12
Defining the Callbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-13
Helper Function: Plotting the Plot Types . . . . . . . . . . . . . . 15-17
GUI that Displays and Graphs Tabular Data . . . . . . . . . 15-18
About the tableplot Example . . . . . . . . . . . . . . . . . . . . . . . . 15-18
Viewing and Running the tableplot GUI M-File . . . . . . . . . 15-22
Setting Up and Interacting with the uitable . . . . . . . . . . . . 15-23
Subfunction Summary for tableplot . . . . . . . . . . . . . . . . . . . 15-29
Further Explorations with tableplot . . . . . . . . . . . . . . . . . . 15-29
A GUI That Manages List Data . . . . . . . . . . . . . . . . . . . . . . 15-32
About the List Master Example . . . . . . . . . . . . . . . . . . . . . . 15-32
Viewing and Running the List Master GUI M-File . . . . . . 15-35
Using List Master . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-36
Programming List Master . . . . . . . . . . . . . . . . . . . . . . . . . . 15-41
Adding an “Import from File” Option to List Master . . . . . 15-49
Adding a “Rename List” Option to List Master . . . . . . . . . . 15-49
Color Palette . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-50
About the Color Palette Example . . . . . . . . . . . . . . . . . . . . . 15-50
Techniques Used in the Color Palette Example . . . . . . . . . 15-54
Viewing and Running the Color Palette GUI M-File . . . . . 15-54
Subfunction Summary for Color Palette . . . . . . . . . . . . . . . 15-55
M-File Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-56
GUI Programming Techniques . . . . . . . . . . . . . . . . . . . . . . . 15-57
Icon Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-62
About the Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-62
Viewing and Running the Icon Editor GUI M-Files . . . . . . 15-64
Subfunction Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-67
M-File Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-69
GUI Programming Techniques . . . . . . . . . . . . . . . . . . . . . . . 15-69
Examples
A
Simple Examples (GUIDE) . . . . . . . . . . . . . . . . . . . . . . . . . . A-2
xvi Contents
Simple Examples (Programmatic) . . . . . . . . . . . . . . . . . . . A-2
Application Examples (GUIDE) . . . . . . . . . . . . . . . . . . . . . A-2
Programming GUI Components (GUIDE) . . . . . . . . . . . . A-2
Application-Defined Data (GUIDE) . . . . . . . . . . . . . . . . . . A-3
GUI Layout (Programmatic) . . . . . . . . . . . . . . . . . . . . . . . . A-3
Programming GUI Components (Programmatic) . . . . . A-3
Application-Defined Data (Programmatic) . . . . . . . . . . . A-4
Application Examples (Programmatic) . . . . . . . . . . . . . . A-4
Index
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。