MATLAB SIMULINK 7 - GRAPHICAL USER INTERFACE Spezifikationen

Stöbern Sie online oder laden Sie Spezifikationen nach Software MATLAB SIMULINK 7 - GRAPHICAL USER INTERFACE herunter. MATLAB SIMULINK 7 - GRAPHICAL USER INTERFACE Specifications Benutzerhandbuch

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 216
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen

Inhaltsverzeichnis

Seite 1 - Version 7

Creating Graphical User InterfacesVersion 7MATLAB®The Language of Technical Computing

Seite 2 - How to Contact The MathWorks:

1 Getting Started with GUIDE1-2What Is GUIDE?GUIDE, the MATLAB® Graphical User Interface development environment, provides a set of tools for creating

Seite 3 - Contents

3 Laying Out GUIs and Setting Properties3-50Set the following panel properties:•BorderType beveledout• BorderWidth 2• HighlightColor (white)-red 1.0-

Seite 4

Setting Component Properties — The Property Inspector3-51Callback PropertiesA callback is a function that executes when a user performs a specific act

Seite 5

3 Laying Out GUIs and Setting Properties3-52The following table lists the various callback properties and briefly describes the purpose of each callba

Seite 6

Setting Component Properties — The Property Inspector3-53• In the View menu, select View Callbacks. Then select the desired callback, e.g., KeyPressFc

Seite 7

3 Laying Out GUIs and Setting Properties3-54Making the Change in the Property Editor. For example, to change the callback name in a push button’s call

Seite 8

Setting Component Properties — The Property Inspector3-55• References in the M-file to the field of the handles structure that contains the component’

Seite 9 - Getting Started with

3 Laying Out GUIs and Setting Properties3-56Viewing the Object Hierarchy — The Object BrowserThe Object Browser displays a hierarchical list of the ob

Seite 10 - 1 Getting Started with GUIDE

Creating Menus — The Menu Editor3-57Creating Menus — The Menu EditorMATLAB enables you to create two kinds of menus:• Menu bar objects — drop-down men

Seite 11 - Starting GUIDE

3 Laying Out GUIs and Setting Properties3-58Defining Menus for the Menu BarWhen you create a drop-down menu, MATLAB adds its title to the figure menu

Seite 12

Creating Menus — The Menu Editor3-59Adding Items to a MenuUse the New Menu Item tool to define the menu items that are displayed in the drop-down menu

Seite 13 - The Layout Editor

Starting GUIDE1-3Starting GUIDETo start GUIDE, enter guide at the MATLAB prompt. This displays the GUIDE Quick Start dialog, as shown in the following

Seite 14

3 Laying Out GUIs and Setting Properties3-60For example, to add an Open menu item under File, select File then click the New Menu Item tool. Fill in t

Seite 15 - GUIDE Templates

Creating Menus — The Menu Editor3-61To create additional drop-down menus, use the New Menu tool in the same way you did to create the File menu. For e

Seite 16

3 Laying Out GUIs and Setting Properties3-62When you run the GUI, the menu titles appear in the menu bar.

Seite 17 - GUI FIG-Files and M-Files

Creating Menus — The Menu Editor3-63Menu CallbacksBy default, the Callback text field in the Menu Editor is set to the string %automatic. This causes

Seite 18

3 Laying Out GUIs and Setting Properties3-64Syntax of the Callback SubfunctionThe GUI M-file contains all callbacks for the GUI, including the menu ca

Seite 19 - Programming the GUI M-file

Creating Menus — The Menu Editor3-65This is the automatically generated callback subfunction that you see if you click the View button after saving th

Seite 20

3 Laying Out GUIs and Setting Properties3-66Note You must select the Menu Editor’s Context Menus tab before you begin to define a context menu.Select

Seite 21

Creating Menus — The Menu Editor3-67You can also • Select the Separator above this item check box to display a separator above the menu item when the

Seite 22

3 Laying Out GUIs and Setting Properties3-68endThis changes the value of the Checked property of the menu item from on to off or vice versa each time

Seite 23 - Creating a GUI

Setting the Tab Order — The Tab Order Editor3-69Setting the Tab Order — The Tab Order EditorA GUI’s tab order is the order in which components of the

Seite 24 - 2 Creating a GUI

1 Getting Started with GUIDE1-4The Layout EditorWhen you open a GUI in GUIDE, it is displayed in the Layout Editor, which is the control panel for all

Seite 25 - Laying Out the GUI

3 Laying Out GUIs and Setting Properties3-70To examine and change the tab order of the panel components, click the panel background to select it, then

Seite 26

4Programming GUIsUnderstanding the GUI M-File (p. 4-2) The GUI M-file programs the GUI. This section describes the functioning of the GUI M-file, bot

Seite 27

4 Programming GUIs4-2Understanding the GUI M-FileThe GUI M-file generated by GUIDE controls the GUI and determines how it responds to a user’s action,

Seite 28

Understanding the GUI M-File4-3You can retrieve the data in any other callback with the commandX = handles.current_data;For an example of sharing data

Seite 29 - Add the Components

4 Programming GUIs4-4• Callbacks — execute each time the user activates the corresponding component of the GUI.Common Input ArgumentsAll functions in

Seite 30

Understanding the GUI M-File4-5my_gui('Position', [71.8 44.9 74.8 19.7]) opens the GUI at the specified position, since Position is a valid

Seite 31 - Align the Components

4 Programming GUIs4-6For example, if the GUI contains a push button whose String property is 'Yes', add the following code to its callback t

Seite 32

Understanding the GUI M-File4-7Input and Output ArgumentsThe following examples illustrate various ways to call a GUI named my_gui with different argu

Seite 33 - Name Property

4 Programming GUIs4-8Programming Callbacks for GUI ComponentsThis section explains how to program the callbacks for some specific GUI components. “Cal

Seite 34

Programming Callbacks for GUI Components4-9% toggle button is pressedelseif button_state == get(hObject,'Min')% toggle button is not pressed

Seite 35

The Layout Editor1-5You can also use the Layout Editor to set basic properties of the GUI components. To learn more about the Layout Editor, see “Usin

Seite 36

4 Programming GUIs4-10Note If you have radio buttons that are managed by a button group component, you must include the code to control them in the b

Seite 37

Programming Callbacks for GUI Components4-11You can use the following code in the edit text callback. It gets the value of the String property and con

Seite 38

4 Programming GUIs4-12callback can query the Selection Type property to determine if it was a single- or double-click. List Box ExamplesSee the follow

Seite 39 - Programming the GUI

Programming Callbacks for GUI Components4-13% proceed with callback...PanelsPanels group GUI components and can make a user interface easier to unders

Seite 40

4 Programming GUIs4-14radio button. It then uses the Tag property of the selected object to choose the appropriate code to execute.function uibuttongr

Seite 41

Programming Callbacks for GUI Components4-15Note If your GUI is opened as the result of another GUI’s callback, you might need to explicitly specify

Seite 42

4 Programming GUIs4-16The preceding code performs the following operations:• Reads the image file banner.jpg using the command imread.• Determines the

Seite 43 - % hObject handle to figure

Programming Callbacks for GUI Components4-17ActiveX ControlsYou can insert an ActiveX control into your GUI if you are running MATLAB on Microsoft Win

Seite 44

4 Programming GUIs4-182 Scroll down the ActiveX Control List and select Mwsamp Control. This displays a preview of the ActiveX control Mwsamp, as show

Seite 45 - Mesh push button callback:

Programming Callbacks for GUI Components4-194 Click the Run button on the toolbar and save the GUI when prompted. GUIDE displays the GUI shown in the

Seite 46

1 Getting Started with GUIDE1-6GUIDE TemplatesThe GUIDE Quick Start dialog provides templates for several basic types of GUIs. The advantage of using

Seite 47

4 Programming GUIs4-20from the View menu. This displays the Property Inspector, as shown in the following figure.The ActiveX control mwsamp has just t

Seite 48

Programming Callbacks for GUI Components4-21refresh(handles.figure1);4 Add the following command to the opening function:handles.activex1.label = ...[

Seite 49 - Saving and Running a GUI

4 Programming GUIs4-22handles.activex1.radius = ...get(hObject, 'Value')*handles.default_radius;handles.activex1.label = ...['Radius =

Seite 50

Programming Callbacks for GUI Components4-23- Gets the Value of the slider, which in this example is a number between 0 and 1, the default values of t

Seite 51 - Setting Properties

4 Programming GUIs4-24Alternatively, you can entermethods(hObject)which displays the available methods in the Command Window.For more information abou

Seite 52 - Using GUIDE Templates

Programming Callbacks for GUI Components4-25hidden from plotting commands issued by your GUI. To issue plotting commands from your GUI, • Create a fig

Seite 53 - Blank GUI

4 Programming GUIs4-26Managing GUI Data with the Handles StructureGUIDE provides a mechanism, called the handles structure, for storing and retrieving

Seite 54 - GUI with Uicontrols

Managing GUI Data with the Handles Structure4-27 Defining the Data Fields in the Opening FunctionThe GUI records the number of times a user enters an

Seite 55 - GUI with Axes and Menu

4 Programming GUIs4-28num2str(get(handles.slider1,'Value')));The code combines three commands:• The get command obtains the current value of

Seite 56 - Modal Question Dialog

Managing GUI Data with the Handles Structure4-29Application DataApplication data provides a way for applications to save and retrieve data stored with

Seite 57

GUIDE Templates1-7To display the names of the GUI components in the component palette, select Preferences from the File menu, check the box next to Sh

Seite 58 - Yes and No push buttons:

4 Programming GUIs4-30Designing for Cross-Platform CompatibilityYou can use specific property settings to create a GUI that behaves more consistently

Seite 59 - Using the Layout Editor

Designing for Cross-Platform Compatibility4-31Specifying a Fixed-Width FontIf you want to use a fixed-width font for a uicontrol, set its FontName pro

Seite 60 - Layout Area

4 Programming GUIs4-32on UNIX). When your GUI is deployed on a different platform, it uses that computer’s standard color. This provides a consistent

Seite 61 - Edit Text

Types of Callbacks4-33Types of CallbacksThe primary mechanism for implementing a GUI is programming the callbacks of the GUI components used to build

Seite 62

4 Programming GUIs4-34Callbacks for Specific ComponentsSome components have additional properties that execute callback routines with the appropriate

Seite 63 - ActiveX Component

Interrupting Executing Callbacks4-35Interrupting Executing CallbacksBy default, MATLAB allows an executing callback to be interrupted by subsequently

Seite 64

4 Programming GUIs4-36• drawnow• figure •getframe• pause• waitforWhen MATLAB encounters one of these commands in a callback, it suspends execution and

Seite 65

Interrupting Executing Callbacks4-372 If the event at the top of the queue calls for a figure window redraw, MATLAB performs the redraw and proceeds t

Seite 66 - Adding an ActiveX Control

4 Programming GUIs4-38Controlling Figure Window BehaviorWhen designing a GUI you need to consider how you want the figure window to behave. The approp

Seite 67 - Moving Components

Controlling Figure Window Behavior4-39the initialization section of the GUI M-file in the opening function with the set command.set(hObject,'Wind

Seite 68

1 Getting Started with GUIDE1-8Running a GUITo run a GUI, select Run from the Tools menu, or click the run button on the toolbar. This displays the

Seite 69

4 Programming GUIs4-40Example: Using the Modal Dialog to Confirm an OperationThis example illustrates how to use the modal dialog GUI together with an

Seite 70

Example: Using the Modal Dialog to Confirm an Operation4-41Note The following links execute MATLAB commands and are designed to work within the MATLA

Seite 71 - Renaming GUI Files

4 Programming GUIs4-42Setting Up the GUI with the Close ButtonTo set up the second GUI with a Close button, do the following:1 Select New from the Fil

Seite 72 - Displaying the GUI

Example: Using the Modal Dialog to Confirm an Operation4-43% eventdata reserved - to be defined in a future version of MATLAB% handles structure w

Seite 73 - Layout Editor Context Menus

4 Programming GUIs4-44Clicking the Yes button closes both the close dialog and the GUI that calls it. Clicking the No button closes just the dialog.Ho

Seite 74 - Component Context Menus

Example: Using the Modal Dialog to Confirm an Operation4-454 When a user clicks one of the two push buttons, the callback for the push button- Updates

Seite 75 - Selecting GUI Options

4 Programming GUIs4-46

Seite 76 - Resize Behavior

5GUI ApplicationsGUI with Multiple Axes (p. 5-2) Analyze data and generate frequency and time domain plots in the GUI figure.List Box Directory Reade

Seite 77 - Command-Line Accessibility

5 GUI Applications5-2GUI with Multiple AxesThis example creates a GUI that contains two axes for plotting data. For simplicity, this example obtains d

Seite 78 - Access Options

GUI with Multiple Axes5-3View Completed Layout and Its GUI M-FileIf you are reading this in the MATLAB Help browser, you can click the following links

Seite 79 - Generate FIG-File and M-File

GUI FIG-Files and M-Files1-9GUI FIG-Files and M-FilesGUIDE stores a GUI in two files, which are generated the first time you save or run the GUI: • A

Seite 80 - Callback Function Syntax

5 GUI Applications5-4To create the default values, set the String property of the edit text. The following figure shows the value set for the time vec

Seite 81

GUI with Multiple Axes5-5For example, the Tag of the axes used to display the FFT is set to frequency_axes. Therefore, within a callback, you access i

Seite 82

5 GUI Applications5-6like you would on the command line. Note that Callback is the default setting for command-line accessibility.See “Selecting GUI O

Seite 83 - Generate FIG-File Only

GUI with Multiple Axes5-7• Making the appropriate axes current using the axes command and the handle of the axes. For example,axes(handles.frequency_a

Seite 84

5 GUI Applications5-8plot(t,x)set(handles.time_axes,'XMinorTick','on')grid on

Seite 85 - Align Options

List Box Directory Reader5-9List Box Directory ReaderThis example uses a list box to display the files in a directory. When the user double clicks on

Seite 86 - Grids and Rulers

5 GUI Applications5-10Note The following links execute MATLAB commands and are designed to work within the MATLAB Help browser. If you are reading th

Seite 87 - Creating Guide Lines

List Box Directory Reader5-11• First input argument is not a directory, but is a character string and there is more than one argument — execute the su

Seite 88 - Front-to-Back Positioning

5 GUI Applications5-12• Change to the specified directory so the GUI can navigate up and down the tree as required.• Use the dir command to get a list

Seite 89

List Box Directory Reader5-13is a file, it is passed to the open command; if it is a directory, the GUI changes to that directory and lists its conten

Seite 90 - Inspect Properties from the

1 Getting Started with GUIDE1-10Programming the GUI M-fileAfter laying out your GUI, you can program the GUI M-file using the M-file editor. GUIDE aut

Seite 91

5 GUI Applications5-14index_selected = get(handles.listbox1,'Value');file_list = get(handles.listbox1,'String');filename = file_li

Seite 92 - Some Commonly Used Properties

Accessing Workspace Variables from a List Box5-15Accessing Workspace Variables from a List BoxThis GUI uses a list box to display workspace variables,

Seite 93 - Callback

5 GUI Applications5-16• Delete the string assigned to the list box Callback property.View Completed Layout and Its GUI M-FileIf you are reading this i

Seite 94 - Setting List Box Properties

Accessing Workspace Variables from a List Box5-17Reading the Selections from the List BoxThis GUI requires the user to select two variables from the w

Seite 95 - Setting Slider Properties

5 GUI Applications5-18var1 = list_entries{index_selected(1)};var2 = list_entries{index_selected(2)};end Callbacks for the Plotting ButtonsThe callback

Seite 96

A GUI to Set Simulink Model Parameters5-19A GUI to Set Simulink Model Parameters This example illustrates how to create a GUI that sets the parameters

Seite 97

5 GUI Applications5-20all component properties and to understand how the components are assembled to create the GUI. You can also see a complete listi

Seite 98

A GUI to Set Simulink Model Parameters5-21Running the SimulationOnce you have set the gain values, you can run the simulation by clicking the Simulate

Seite 99

5 GUI Applications5-22• Determine if the model is open (find_system).• Open the block diagram for the model and the subsystem where the parameters are

Seite 100

A GUI to Set Simulink Model Parameters5-23• Calls model_open to ensure that the Simulink model is open so that simulation parameters can be set.• Gets

Seite 101 - Callback Properties

Programming the GUI M-file1-11You can view the callback for any of the GUI components by clicking the function icon on the toolbar. This displays a l

Seite 102

5 GUI Applications5-24• Sets the appropriate block parameter to the new value (set_param).Here is the callback for the Kf Current value text box.funct

Seite 103 - Changing Callback Properties

A GUI to Set Simulink Model Parameters5-25Here is the Simulate and store results button callback.function SimulateButton_Callback(hObject, eventdata,

Seite 104

5 GUI Applications5-26endset(handles.ResultsList,'String',ResultsStr);% Store the new ResultsDatahandles.ResultsData = ResultsData;guidata(h

Seite 105

A GUI to Set Simulink Model Parameters5-27set(handles.ResultsList,'Value',currentVal,'String',resultsStr)% Store the new ResultsDa

Seite 106

5 GUI Applications5-28currentVal = get(handles.ResultsList,'Value');% Get data to plot and generate command string with color% specifiedlege

Seite 107

A GUI to Set Simulink Model Parameters5-29The GUI Help ButtonThe GUI Help button callback displays an HTML file in the MATLAB Help browser. It uses tw

Seite 108 - Specifying Menu Properties

5 GUI Applications5-30when you add the list box and automatically sets the Callback property to execute this subfunction whenever the callback is trig

Seite 109 - Adding Items to a Menu

An Address Book Reader5-31An Address Book ReaderThis example shows how to implement a GUI that displays names and phone numbers, which it reads from a

Seite 110

5 GUI Applications5-32• The names and phone numbers stored in the MAT-file• An index pointer that indicates the current name and phone number, which m

Seite 111 - Laying Out Three Menus

An Address Book Reader5-33• GUI M-file options selected: Generate callback function prototypesApplication allows only one instance to runCalling the G

Seite 112

How to Contact The MathWorks:www.mathworks.com Webcomp.soft-sys.matlab [email protected] Technical [email protected] Product

Seite 113 - Menu Callbacks

1 Getting Started with GUIDE1-12Editing Version 5 GUIs with Version 7 GUIDEIn MATLAB Version 5, GUIDE saved GUI layouts as MAT-file/M-file pairs. Sinc

Seite 114 - Select All uimenu item

5 GUI Applications5-34elseif (length(varargin) == 2 & strcmpi(varargin{1},'book') & (2 == exist(varargin{2},'file'))) C

Seite 115 - Defining Context Menus

An Address Book Reader5-35Check_And_Load Code ListingThis is the Check_And_Load function.function pass = Check_And_Load(file,handles)% Initialize the

Seite 116 - New Menu Item

5 GUI Applications5-36elseerrordlg('Not a valid Address Book','Address Book Error')endThe Open Menu CallbackThe address book GUI c

Seite 117

An Address Book Reader5-37• If the name exists in the current address book, the corresponding phone number is displayed.• If the name does not exist,

Seite 118 - UIContextMenu property

5 GUI Applications5-38returnendend% If it's a new name, ask to create a new entryAnswer=questdlg('Do you want to create a new entry?',

Seite 119

An Address Book Reader5-39Code Listingfunction Contact_Phone_Callback(hObject, eventdata, handles)Current_Phone = get(handles.Contact_Phone,'stri

Seite 120 - 3 Mesh push button

5 GUI Applications5-40Determining Which Button Is ClickedThe callback defines an additional argument, str, that indicates which button, Prev or Next,

Seite 121 - Programming GUIs

An Address Book Reader5-41% last element in the Addresses arrayif i < 1i = length(Addresses);endcase 'Next'% Increase the index by onei =

Seite 122 - 4 Programming GUIs

5 GUI Applications5-42Saving the MAT-FileIf the user selects Save, the save command is called to save the current MAT-file with the new names and phon

Seite 123 - Accessing GUI Data

An Address Book Reader5-43endendThe Create New MenuThe Create New menu simply clears the Contact Name and Contact Phone # text fields to facilitate ad

Seite 124

Editing Version 5 GUIs with Version 7 GUIDE1-13M-file generated by Version 7 GUIDE can provide a model of how to restructure your code.

Seite 125 - Output Function

5 GUI Applications5-44The size of the Contact Name text box changes in proportion to the new figure width. This is accomplished by:• Changing the Unit

Seite 126

An Address Book Reader5-45if Figure_Size(3) < Original_Size(3)% If the width is too small then reset to origianl widthset(hObject, 'Position&a

Seite 128

Index-1IndexAactivate figure 3-19ActiveX controls 4-17aligning GUI components 3-34Alignment Tool, for GUIs 3-34application data 4-29application M-file

Seite 129 - Radio Buttons

IndexIndex-2GUIDE (continued)creating menus 3-57demonstration 2-3editing version 5 GUIs 1-12generated M-file 3-29grids and rulers 3-36GUI background c

Seite 130

IndexIndex-3Ttoggle buttons 4-8toolbar menuscreating with GUIDE 3-58

Seite 132

1 Getting Started with GUIDE1-14

Seite 133 - Button Groups

2Creating a GUIDesigning the GUI (p. 2-2) Designing the GUI before actually creating it in GUIDE.Laying Out the GUI (p. 2-3) Using the GUIDE Layout E

Seite 134

2 Creating a GUI2-2Designing the GUIThe GUI used in this example contains an axes that displays either a surface, mesh, or contour plot of data select

Seite 135

Laying Out the GUI2-3Laying Out the GUIThis section illustrates how to lay out GUI components (i.e., a panel, axes, and user interface controls, such

Seite 136

2 Creating a GUI2-4Open a New GUI in the Layout EditorOpen GUIDE by typing guide at the MATLAB prompt. This displays the Guide Quick Start dialog show

Seite 137 - ActiveX Controls

Laying Out the GUI2-5To display the names of the GUI components in the component palette, select Preferences from the File menu, check the box next to

Seite 138

2 Creating a GUI2-6Set the GUI Figure SizeSpecify the size of the GUI by resizing the grid area in the Layout Editor. Click on the lower-right corner

Seite 139 - Layout Editor and select

Laying Out the GUI2-7Note Setting the Units property to characters gives the GUI a more consistent appearance across platforms.Add the Components1 Ad

Seite 140

iContents1Getting Started with GUIDEWhat Is GUIDE? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2Starting GUIDE

Seite 141 - M-file Editor

2 Creating a GUI2-8push buttons into the panel. As you move each push button into the panel, GUIDE highlights the panel to indicate that the panel is

Seite 142

Laying Out the GUI2-9Align the ComponentsYou can use the Alignment Tool to align components with respect to one another if they have the same parent.

Seite 143

2 Creating a GUI2-10Now align the tops of the axes and the panel. Note that when the panel moves, its contents move with it.To learn more about the La

Seite 144

Setting Properties for GUI Components2-11Setting Properties for GUI ComponentsTo set the properties of each GUI component, select the Property Inspect

Seite 145

2 Creating a GUI2-12Title PropertyA panel’s Title property controls the title that appears at the top or bottom of the panel. Select the panel in the

Seite 146

Setting Properties for GUI Components2-13When you click on the Layout Editor, the current layout of the GUI appears as in the following figure.

Seite 147

2 Creating a GUI2-14Callback PropertiesComponents use callbacks to do their work. A callback is a function that executes when a user performs a specif

Seite 148

Setting Properties for GUI Components2-15When you first add a component to a layout, GUIDE sets the value of Tag to a default string such as pushbutto

Seite 149 - Application Data

2 Creating a GUI2-16You can redefine the value of Tag to be more descriptive, but the value of each Tag property must be unique for a given GUI. In th

Seite 150

Programming the GUI2-17Programming the GUIAfter laying out the GUI and setting component properties, the next step is to program it. This section expl

Seite 151 - Using a Specific Font Name

ii ContentsSetting Properties for GUI Components . . . . . . . . . . . . . . . . 2-11Name Property . . . . . . . . . . . . . . . . . . . . . . . .

Seite 152

2 Creating a GUI2-18cursor to a specific callback by clicking the function icon on the toolbar, then selecting the callback you want in the pop-up m

Seite 153 - Types of Callbacks

Programming the GUI2-19Sharing Data Between CallbacksThis topic describes the process for sharing data between callbacks in a GUI. Subsequent topics,

Seite 154

2 Creating a GUI2-20Note To save any changes that you make to the handles structure, you must use the command guidata(hObject,handles). It is not suf

Seite 155 - The Event Queue

Programming the GUI2-21% This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in a futur

Seite 156

2 Creating a GUI2-22The following figure shows how the GUI now looks when it first displays.Adding Code to the CallbacksWhen the GUI is completed and

Seite 157 - BusyAction

Programming the GUI2-23Add the code after the comments following the function definition, as shown below:Surf push button callback:% --- Executes on b

Seite 158

2 Creating a GUI2-24Add this code to the Contour push button callback:% Display contour plot of the currently selected datacontour(handles.current_dat

Seite 159 - Dismissing a Modal Figure

Programming the GUI2-25properties of each component of the GUI. Selecting the name of a component in the list also selects the component in the Layout

Seite 160

2 Creating a GUI2-26Saving and Running a GUIAfter writing the callbacks, you can run the GUI by selecting Run from the Tools menu or clicking the Run

Seite 161

Saving and Running a GUI2-27Note The name of the FIG-file saved by the Layout Editor and the generated M-file must match. See “Renaming GUI Files” if

Seite 162

iiiLayout Editor Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-22Layout Editor Context Menus . . . . . . . . . . . . . . .

Seite 163

2 Creating a GUI2-28Try experimenting with this GUI by adding another data set in the opening function, and a push button that displays a plot of the

Seite 164

3Laying Out GUIs and Setting Properties Using GUIDE Templates (p. 3-2) Overview of GUIDE templates — simple GUIs that you modify to create your own G

Seite 165

3 Laying Out GUIs and Setting Properties3-2Using GUIDE TemplatesGUIDE provides several templates, which are simple examples that you can modify to cre

Seite 166

Using GUIDE Templates3-3right pane. Clicking OK opens the GUI template in the Layout Editor. If you select Save on startup as and type in name in the

Seite 167 - GUI Applications

3 Laying Out GUIs and Setting Properties3-4Select the blank GUI if the other templates are not suitable starting points for the GUI you are creating,

Seite 168 - 5 GUI Applications

Using GUIDE Templates3-5When a user enters values for the density and volume of an object, and clicks the Calculate button, the GUI calculates the mas

Seite 169 - Design of the GUI

3 Laying Out GUIs and Setting Properties3-6You can select other plots in the pop-up menu. Clicking the Update button displays the currently selected p

Seite 170

Using GUIDE Templates3-7Running the GUI displays the dialog shown in the following figure:The GUI returns the text string Yes or No, depending on whic

Seite 171 - GUI Option Settings

3 Laying Out GUIs and Setting Properties3-8To restore access to other MATLAB windows once a button is clicked, add the following command to callbacks

Seite 172

Using the Layout Editor3-9Using the Layout EditorThe Layout Editor enables you to select GUI components from the component palette, at the left side o

Seite 173 - Plot Button Code Listing

iv Contents4Programming GUIsUnderstanding the GUI M-File . . . . . . . . . . . . . . . . . . . . . . . . . 4-2Sharing Data with the Handles Structu

Seite 174

3 Laying Out GUIs and Setting Properties3-10If you want to load an existing GUI for editing, typeguide filename.figor use Open from the File menu on t

Seite 175 - List Box Directory Reader

Using the Layout Editor3-11After selecting the components for your GUI and placing them in the layout area, you need to set their properties and progr

Seite 176

3 Laying Out GUIs and Setting Properties3-12single-line edit text, Ctl+Enter for a multi-line edit text, or the focus moves away.Static TextStatic tex

Seite 177 - Loading the List Box

Using the Layout Editor3-13Button GroupButton groups are like panels but can be used to manage exclusive selection behavior for radio buttons and togg

Seite 178

3 Laying Out GUIs and Setting Properties3-14 Adding a Component to a Panel or Button GroupTo add a component to a panel or button group, select the

Seite 179

Using the Layout Editor3-15If the component is not entirely contained in the panel or button group, it appears to be clipped in the layout editor.When

Seite 180

3 Laying Out GUIs and Setting Properties3-16You can use the Object Browser to determine the child objects of a panel or button group. “Viewing the Obj

Seite 181

Using the Layout Editor3-17Selecting ComponentsYou can select components in the layout area in the following ways. • Click a single component to selec

Seite 182

3 Laying Out GUIs and Setting Properties3-18panel, or button group from which you move them, even if they move outside its boundaries.Copying, Cutting

Seite 183 - Enabling Multiple Selection

Using the Layout Editor3-19• Right-click and drag the component to the desired location. The position of the cursor when you drop the components deter

Seite 184

vInterrupting Executing Callbacks . . . . . . . . . . . . . . . . . . . . . 4-35Controlling Interruptibility . . . . . . . . . . . . . . . . . . .

Seite 185

3 Laying Out GUIs and Setting Properties3-20Replace — writes over the existing file.Append — inserts new callbacks for components added since the last

Seite 186

Using the Layout Editor3-21Note GUIDE automatically saves both the M-file and the FIG-file when you run the GUI.Saving the LayoutOnce you have create

Seite 187 - Running the GUI

3 Laying Out GUIs and Setting Properties3-224 Save the exported M-file in the Save As dialog. By default, GUIDE gives the exported M-file the name of

Seite 188

Using the Layout Editor3-23Layout Editor Context MenusWhen working in the Layout Editor, you can select an object with the left mouse button and then

Seite 189 - 'String',NewVal)

3 Laying Out GUIs and Setting Properties3-24Component Context MenusThe following picture shows the context menu associated with user interface control

Seite 190

Selecting GUI Options3-25Selecting GUI OptionsAfter opening a new GUI template in the Layout Editor, but before saving the GUI, you can configure the

Seite 191

3 Laying Out GUIs and Setting Properties3-26Resize BehaviorYou can control whether users can resize the figure window containing your GUI and how MATL

Seite 192

Selecting GUI Options3-27Property Settings. GUIDE sets the following properties to create proportional resizing GUIs:•Units properties of the axes, us

Seite 193 - Plotting the Results Data

3 Laying Out GUIs and Setting Properties3-28such as plot, that alter the current figure. With the default option, which is Callback (GUI becomes Curre

Seite 194

Selecting GUI Options3-29HandleVisibility — Callback. Setting HandleVisibility to callback causes handles to be visible from within callback routines

Seite 195 - Closing the GUI

vi ContentsA GUI to Set Simulink Model Parameters . . . . . . . . . . . . . . 5-19Techniques Used in This Example . . . . . . . . . . . . . . . .

Seite 196

3 Laying Out GUIs and Setting Properties3-30Generate Callback Function PrototypesWhen you select Generate callback function prototypes in the GUI Opti

Seite 197 - An Address Book Reader

Selecting GUI Options3-31function pushbutton1_Callback(hObject, eventdata, handles)Assigning a Callback Property StringWhen you first add a component

Seite 198

3 Laying Out GUIs and Setting Properties3-32GUI Allows Only One Instance to Run (Singleton)This option allows you to select between two behaviors for

Seite 199 - Calling the GUI

Selecting GUI Options3-33Generate FIG-File OnlySelect Generate FIG-file only in the GUI Options dialog if you do not want GUIDE to generate the M-file

Seite 200

3 Laying Out GUIs and Setting Properties3-34Aligning Components in the Layout EditorYou can select and drag any component or group of components that

Seite 201 - Check_And_Load Code Listing

Aligning Components in the Layout Editor3-35The alignment tool provides two types of alignment operations:•Align — align all selected components to a

Seite 202

3 Laying Out GUIs and Setting Properties3-36All of the align options (vertical top, center, bottom and horizontal left, center, right) place the selec

Seite 203 - Contact Name Callback

Aligning Components in the Layout Editor3-37number of other values ranging from 10 to 200 pixels. You can optionally enable snap-to-grid, which causes

Seite 204

3 Laying Out GUIs and Setting Properties3-38Front-to-Back PositioningMATLAB figures maintain separate stacks that control the front-to-back positionin

Seite 205 - Code Listing

Aligning Components in the Layout Editor3-39The Layout Editor provides four operations that enable you to control front-to-back positioning:• Bring to

Seite 206

1Getting Started with GUIDEWhat Is GUIDE? (p. 1-2) An introduction to GUIDEStarting GUIDE (p. 1-3) How to start GUIDE and use the Quick Start dialogT

Seite 207 - Save or Save As

3 Laying Out GUIs and Setting Properties3-40Setting Component Properties — The Property InspectorThe Property Inspector enables you to set the propert

Seite 208

Setting Component Properties — The Property Inspector3-41To change a property, click in the field to the right of the property name, delete its curren

Seite 209 - The Create New Menu

3 Laying Out GUIs and Setting Properties3-42Some Commonly Used PropertiesAs examples, this section describes four important and commonly used properti

Seite 210

Setting Component Properties — The Property Inspector3-43CallbackThe Callback property specifies the callback that is executed in the GUI M-file when

Seite 211

3 Laying Out GUIs and Setting Properties3-44Setting Radio Button PropertiesRadio buttons have two states — selected and not selected. You can query an

Seite 212

Setting Component Properties — The Property Inspector3-45The Value property contains the index into the list of strings that corresponds to the select

Seite 213

3 Laying Out GUIs and Setting Properties3-46Note If you have set units for your GUI to characters, certain combinations of width and height produce a

Seite 214

Setting Component Properties — The Property Inspector3-47The SliderStep property controls the amount the slider Value property changes when you click

Seite 215

3 Laying Out GUIs and Setting Properties3-48Determining Which Item Is Selected. The Value property contains the index of the selected item. For exampl

Seite 216

Setting Component Properties — The Property Inspector3-49• off — The control is disabled and its label (set by the string property) is grayed out.•ina

Kommentare zu diesen Handbüchern

Keine Kommentare