MATLAB SIMULINK 7 - GRAPHICAL USER INTERFACE Betriebsanweisung

Stöbern Sie online oder laden Sie Betriebsanweisung nach Software MATLAB SIMULINK 7 - GRAPHICAL USER INTERFACE herunter. MATLAB SIMULINK 7 - GRAPHICAL USER INTERFACE User`s guide [en] Benutzerhandbuch

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 759
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 0
MATLAB
®
Creating Graphic
al User Interfaces
R2012a
Seitenansicht 0
1 2 3 4 5 6 ... 758 759

Inhaltsverzeichnis

Seite 1 - Creating Graphic

MATLAB®Creating Graphical User InterfacesR2012a

Seite 2 - Natick, MA 01760-2098

Adding Callback Templates to an Existing GUI CodeFile... 8-9About GUIDE-Generated Callbacks...

Seite 3 - Revision History

5 GUIDE Preferences and OptionsGUIDE PreferencesIn this section...“Set P refe rences” on page 5-2“Confirmation Preferences” on page 5-2“Backward Compa

Seite 4

GUIDE PreferencesIn the Preferences dialog box, click General > Confirmation Dialogs toaccess the GUID E confirm ation preferences. Look for the wo

Seite 5

5 GUIDE Preferences and OptionsPrompt to Save on ExportWhen you select Export from the Layout Editor File menu, a dialog boxinforms you of the impendi

Seite 6

GUIDE PreferencesTo make a FIG-file backward compatible, selectFile>Preferences>General>MAT-Files,andthenselectMATLABVersion 5 or later (save

Seite 7 - Create GUIs with GUIDE

5 GUIDE Preferences and OptionsAll Other PreferencesGUIDE p rovides other preferences, for the Layout Editor interface and forinserting code comments.

Seite 8

GUIDE Preferences• “Add Comments for Newly Generated Callback Functions” on page 5-8Show Names in Component PaletteDisplays both icons and names in th

Seite 9 - Save and Run a GUIDE GUI

5 GUIDE Preferences and OptionsAdd Comments for Newly Generated Callback FunctionsCallbacks are blocks of code that execute in response to actions by

Seite 10

GUI OptionsGUI OptionsIn this section...“The GUI O ptions Dialog Box” on page 5-9“Resize Be havior” on page 5-10“Command-Line Accessibility” on page 5

Seite 11 - Examples of GUIDE GUIs

5 GUIDE Preferences and OptionsThe following sectio ns describe the options in this dialog bo x:Resize BehaviorYou cancontrol w hether users can resiz

Seite 12

GUI Optionssee the GUIDE examples “Panel” on page 8-38 and “An Address B ook Reader(GUIDE)” on page 10-81. Also see the example “Using Panel Container

Seite 13 - Create GUIs Programmatically

Data Management Mechanism Summary ... 9-2Nested Functions... 9-4UserData Property...

Seite 14 - Code a Programmatic GUI

5 GUIDE Preferences and OptionsOption DescriptionCallback (GUI becomes CurrentFigure within Callbacks)The GUI can be accessed onlyfrom within a GUI ca

Seite 15 - Manage Callback Execution

GUI OptionsGUIDE also adds a callback whenever you edit a callback routine from theLayout Editor’s right-click context menu and when you add menus to

Seite 16

5 GUIDE Preferences and OptionsUse System Color Scheme for BackgroundThe default color u sed for GUI components is system dependent. This optionenable

Seite 17 - Examples

GUI Optionslimited editing capability and may be useful for GUIs generated in MATLABVersions 5.3 and earlier. See theguide function for more informati

Seite 18 - Contents

5 GUIDE Preferences and Optionsarguments to that function. For example, setting the Callbac k property ofapushbuttontosqrt(2) causes the result of the

Seite 19 - Introduction to Creating GUIs

6Lay Out a GUIDE GUI• “Design a GUI” on page 6-2• “Start GUIDE” on page 6-4• “Select a GUI Template” on page 6-6• “Set the GUI Size” on page 6-15• “Ad

Seite 20

6 Lay Out a GUIDE GUIDesign a GUIBefore creating the actual GUI, it is important to decide what it is you wantyour GUI to do and how you want it to wo

Seite 21 - Software

Design a G UI• AskTog — Essays on good design and a list of FirstPrinciples for good user interface design. The author, BruceTognazzini, is a well-res

Seite 22 - What Is a GUI?

6 Lay Out a GUIDE GUIStar t GUIDEThere are many ways to start GUIDE. You can s tart GUIDE from the:• Command line by typingguide• Start menu by select

Seite 23

Start GUIDE• Open Existing GUI —EnablesyoutoopenanexistingGUIinGUIDE.You can choose a GUI from your current folder or browse other directories.6-5

Seite 24 - 'print')

About the List Box Directory Example ... 10-54View and Run the List Box Directory GUI... 10-55Implement the List Box Directory

Seite 25

6 Lay Out a GUIDE GUISelect a GUI TemplateIn this section...“Access the Templates” on page 6-6“Template Descriptions” on page 6-7Access the TemplatesG

Seite 26 - Where Do I Start?

Select a GUI TemplateTo use a template:1 Select a template in the left pane. A preview displays in the right pane.2 Optionally, name your GUI now by s

Seite 27

6 Lay Out a GUIDE GUIBlank GUIThe blank GUI template displayed in the Layout Editor is shown in thefollowing figure.Select the blank GUI if the other

Seite 28 - Ways to Build MATLAB GUIs

Select a GUI TemplateGUI with UicontrolsThe following figure shows the template for a GUI with user interface controls(uicontrols) displayed in the La

Seite 29 - Ways to Build MATLAB

6 Lay Out a GUIDE GUIWhen you run the GUI by clicking the Run button ,theGUIappearsasshown in the following figure.When a user enters values f or the

Seite 30 - 1 About GUIs in MATLAB

Select a GUI TemplateWhen you run the GUI by clicking the Run button on the toolbar, theGUI d is plays a plot of five lines, each o f which is generat

Seite 31 - How to Create a G UI with

6 Lay Out a GUIDE GUIYou can select other p lo ts in the pop-up menu. Clicking the Up date buttondisplays the currently selected plot on the axes .The

Seite 32 - Introduction to GUIDE

Select a GUI TemplateModal Question DialogThe m odal question dialog template displayed in the Layout Editor is shownin the following figure.Running t

Seite 33

6 Lay Out a GUIDE GUIThe GUI returns the text string Yes or No, depending on which button youclick.Select this template if you want your GUI to return

Seite 34 - Getting Help in GUIDE

Set the GUI SizeSet the GUI SizeSet the size of the GUI by resizing the grid area in the Layout Editor.Click the lower-right corner and drag it until

Seite 35

Run the Close-Confirmation GUI ... 10-102How the Close-Confirmation GUIs Work... 10-103Time Data Updates from a GUI (GUID

Seite 36

6 Lay Out a GUIDE GUINote Many of the following steps show you how to use the P roperty Inspectorto set properties of a GUI and its components. If you

Seite 37 - Laying Out a GUIDE GUI

Set the GUI Size4 Type the x and y coordinates of the point where you w ant the lower-leftcorner of the GUI to appear, and its width and height.5 Rese

Seite 38 - Programming a GUIDE GUI

6 Lay Out a GUIDE GUIMaximize the Layout AreaYou can make maximum use of space within the Layout Editor by hidingthe G UIDE toolbar, status bar, or bo

Seite 39 - Simple GUIDE GUI Components

Add Components to the GUIAdd Components to the GUIIn this section...“Available Com ponents” on page 6-20“A Working GUI with Many Components” on page 6

Seite 40

6 Lay Out a GUIDE GUIAvailable ComponentsThe component palette at th e left side of the Layout Editor contains thecomponents thatyou can add to your G

Seite 41

Add Components to the GUIComponent Icon DescriptionPush Button Push buttons generate an action w h en clicked.For example, an OK button might apply se

Seite 42

6 Lay Out a GUIDE GUIComponent Icon DescriptionPop-Up MenuPop-up menus open to display a list of choiceswhen users click the arrow.List BoxList boxes

Seite 43

Add Components to the GUIComponent Icon DescriptionButton GroupButton groups are like panels but are used tomanage exclusive selection behavior for ra

Seite 44

6 Lay Out a GUIDE GUI• Clickheretodisplaythecontrolsuite GUI in the GUIDE Layout Editor.• Clickheretodisplaythecontrolsuite GUIcodefileintheMATLABEdit

Seite 45 - Add Components t

Add Components to the GUIThe GUI contains 15 controls organized within seven panels. The ActionPanel contains a static text component that changes to

Seite 46 - Align the Components

Set Tab Order in a Programmatic GUI ... 11-70How Tabbing Works... 11-70Default Tab Order...

Seite 47

6 Lay Out a GUIDE GUIRun the controlsuite GUIWhen you click the Run Figure button in the Layout Editor, the GUIopens, initializes, and displays itself

Seite 48 - Add Text to the Components

Add Components to the GUIThe code that generates the message is part of the pushbutton1_Ca llback,shown below :function pushbu tton 1_Callback(hObject

Seite 49

6 Lay Out a GUIDE GUI% hObject handle to togglebutton1 (see GCBO)% eventdata re serv ed - to be defi ned in a future ver sion of MATLAB% handles struc

Seite 50

Add Components to the GUIThe popup’s callback controls its behavior. GUIDE generates this much ofthe callback.function popupm enu1 _Callback(hObject,

Seite 51 - String.TheString

6 Lay Out a GUIDE GUIretrieve the nam e of the colormap That name, selectedTex t,iscomposedinto a message and placed in thetextStatus static text fiel

Seite 52 - Strin g. In the String

Add Components to the GUIFor another example describing how to couple uitables with graphics, see“GUI to Interactively Explore D ata in a T able (GUID

Seite 53

6 Lay Out a GUIDE GUIIf You Are Adding...Then...Panels or butto n groupsSee “Add a Component to a Panelor Button Group” on page 6-34.MenusSee “Create

Seite 54

Add Components to the GUIThis is an example of a GUI in the Layout Editor. Components in the LayoutEditor are not active.Use Coordinates to Place Comp

Seite 55 - .m, contains MATLAB functions

6 Lay Out a GUIDE GUIdistances are relative to the parent figure, panel, or button group. Allvalues are giv en in pix e ls. Rulers also display pix el

Seite 56

Add Components to the GUIGUIDE highlights the potential parent as shown in the following figure. Thehighlight indicates that if you drop the component

Seite 57

Program ActiveX Controls ... 12-34Program M enu Items... 12-34Program Toolbar Tools...

Seite 58 - Program the Simple GUIDE GUI

6 Lay Out a GUIDE GUIInclude Existing Components in Panels and Button Groups. Whenyou add a new component or drag an existing component to a panel orb

Seite 59 - The curs

Add Components to the GUIThe panel highlights when you move a control, indicating it now containsthe control. The Object Browser updates to confirm th

Seite 60 - % uiwait(handles.f igure1);

6 Lay Out a GUIDE GUI3 In the Property Inspector, select Tag and then replace the value with thestringyouwanttouseastheidentifier. Inthefollowingfigur

Seite 61 - Program the Pop-Up Menu

Add Components to the GUI• “Static Text” on page 6-48• “Pop-Up Menu” on page 6-50• “ListBox”onpage6-52• “Toggle Button” on page 6-54Note See “Availabl

Seite 62 - % handles

6 Lay Out a GUIDE GUIPropertyValueDescriptionStringString. Can also be acell array or characterarray of strings.Component label. Forlist boxes and pop

Seite 63 - Program the Push Buttons

Add Components to the GUITo display the & character in a label, use two & characters in the string.The wordsremove, default,andfactory (case s

Seite 64

6 Lay Out a GUIDE GUINote Create your own icon with the icon editor described in “Icon Editor”on page 15-63. Seeind2rgb for information on converting

Seite 65

Add Components to the GUIclicking the trough m oves the slider thumb. Setting it to 1 or higher causesthethumbtomovetoMax or Min w hen the trough is c

Seite 66 - UsetheCompletedSimpleGUIDEGUI

6 Lay Out a GUIDE GUI• Specify the radio button label by setting the String property to the desiredlabel, in this case,Indent neste d functions.To dis

Seite 67

Add Components to the GUI• Ifyouwanttosetthepositionorsizeofthecomponenttoanexactvalue,then modify itsPosition property. See “Locate and Move Componen

Seite 68

GUI with Axes, Menu, and Toolbar ... 15-4About the Axes, M en u, and Toolbar Example... 15-4View and Run the AxesMenuT oolbar C

Seite 69 - GUI Programmatically

6 Lay Out a GUIDE GUITo display the & character in a label, use two & characters in the string.The wordsremove, default,andfactory (case sensi

Seite 70

Add Components to the GUI• Specify the text to be displayed when the edit text component is createdby setting theString property to the d esired strin

Seite 71

6 Lay Out a GUIDE GUIIf Max-Min is less than or equal to 1, the edit text component admits only asingle line of input. If you specify a component widt

Seite 72

Add Components to the GUI• Specify the text that appears in the component by setting the componentString property to the desired text, in this caseSel

Seite 73

6 Lay Out a GUIDE GUI“Edit Text” on page 6-46, and for a programmatic approach, the section“Setting Font Characteristics” on page 11-18.Pop-Up MenuTo

Seite 74

Add Components to the GUITo display the & character in a menu i tem, use two & characters in thestring. The wordsremove, default,andfactory (c

Seite 75

6 Lay Out a GUIDE GUI• If you w ant to set the position and size of the component to exact values,then modify itsPosition property. See “Locate and Mo

Seite 76

Add Components to the GUITo display the & character in a label, use two & characters in the string.The wordsremove, default,andfactory (case s

Seite 77

6 Lay Out a GUIDE GUI- To select more than one item when the component is created, set Valueto a vector of indices of the s elected items. Value = [1,

Seite 78

Add Components to the GUI• Specify the toggle button label b y setting its String property to the desiredlabel, in this case,Left/Right Ti le.To displ

Seite 79

ExamplesASimple Examples (GUIDE) ... A-2Simple Examples (Programmatic)... A-3Application Examples (GUIDE)...

Seite 80

6 Lay Out a GUIDE GUIsoftware sets Value to Max,andtoMin when the user deselects it. Thefollowing figure shows the toggle button in the depressed posi

Seite 81 - CodetheSimpleProgrammaticGUI

Add Components to the GUI1 Use the Property Inspector to modify the appropriate properties. Open theProperty Inspector by selecting Prop erty Insp ect

Seite 82

6 Lay Out a GUIDE GUIProperty Values DescriptionTitlePosition lefttop, centertop ,righttop, leftbott om,centerbottom,rightbottom.Defaultislefttop.Loca

Seite 83

Add Components to the GUI• Specify the panel title by setting the Title property to the desired string,in this caseMy Panel.To display the & chara

Seite 84

6 Lay Out a GUIDE GUI• Ifyouwanttosetthepositionorsizeofthepaneltoanexactvalue,thenmodify itsPosition property. See “Locate and Move Components” on pa

Seite 85

Add Components to the GUITo display the & character in the title, use two & characters in the string.The words remove, default, and factory (c

Seite 86

6 Lay Out a GUIDE GUINote For more information and additional tips and techniques, see“Add a Component to a Panel or Button Group” on page 6-34 and th

Seite 87

Add Components to the GUIProperty Values DescriptionNextPlot add, replace,replacechildren.Default isreplaceSpecifies whetherplotting adds graphics,rep

Seite 88 - Open and Run the GUI

6 Lay Out a GUIDE GUI• Allow for tick marks to be placed outside the box that appears in the LayoutEditor. The axes above looks l ike this in the layo

Seite 89

Add Components to the GUI• Use thetitle, xlabel, ylabel, zlabel,andtext functions in the GU Icode file to label an axes component. For example,xlh = (

Seite 90

xviii Contents

Seite 91

6 Lay Out a GUIDE GUI• If you customize axes properties, some of them ( or example, callbacks, fontcharacteristics, and axis limits and ticks) may get

Seite 92

Add Components to the GUIGroupPropertyValuesDescriptionColumnName1-by-n cell arrayof strings |{’numbered’} |emptymatrix([])The h eader labelof the col

Seite 93 - What Is GUIDE?

6 Lay Out a GUIDE GUIDrag the table icon on to the Layout Editor and right click in the table. SelectTable Property E ditor from its pop-up context me

Seite 94 - GUIDE: Getting Started

Add Components to the GUIUse theTable Property Editor. When you open it this way, the TableProperty Editor displays the Column pane. You can also open

Seite 95 - GUIDE Tools Summar y

6 Lay Out a GUIDE GUIButton PurposeAccelerator KeysWindows MacintoshInsertInserts a new column or rowdefinition entry below the currentoneInsert Inser

Seite 96 - 4 What Is GUIDE?

Add Components to the GUISelect Show names entered below as the column headers and s et theColumnName by entering Rate, Amount, Available, and F ixed/

Seite 97 - GUIDE Tools Summary

6 Lay Out a GUIDE GUIFor the Rate column, select Numeric. For the Amount Column selectCustom and in the C ustom Format Editor, choose Bank.6-72

Seite 98

Add Components to the GUILeave the Available column at the default value. This allows MATLAB tochose based on the value of theData property of the tab

Seite 99 - GUIDE Preferences and

6 Lay Out a GUIDE GUINote The In order for a user to select items from a choice list, theColumnEditable property of the column the list occupies must

Seite 100 - GUIDE Preferences

Add Components to the GUISet Data Properties. Specify the value of the Data you want in the table.You need createData in the MATLAB command window bef

Seite 101 - GUIDE in the

Introduction to Creating GUIsChapter 1, About GUIs inMATLAB Software (p. 1-1)Explains what a GUI is, howaGUIworks,andhowtogetstarted creating a GUI.Ch

Seite 102 - Prompt to Save on Export

6 Lay Out a GUIDE GUISet Color Properties. Specify the Bac kgroundColor and RowStriping foryour table in the Color tab.6-76

Seite 103

Add Components to the GUIYou can change other uitable properties to the table via the PropertyInspector.Add ActiveX ControlsWhen you drag a n A ctiveX

Seite 104 - All Other Preferences

6 Lay Out a GUIDE GUINote If MATLAB software is not installed locally on your computer — forexample, if you are running the software over a network —

Seite 105 - .fig ,intheLayout

Add Components to the GUI2 Click Create. The control appears as a small box in the Layout Editor.3 Resize the control to approximately the size of the

Seite 106 - GUIDE Preferences and Options

6 Lay Out a GUIDE GUI• “Select Components” on page 6-80• “Copy, Cut, and Clear Components” on page 6-81• “Paste and Duplicate Components” on page 6-81

Seite 107 - GUI Options

Add Components to the GUINote You can select multiple components onlyiftheyhavethesameparent.To determ ine the child objects of a figure, panel, or bu

Seite 108 - ResizeFcn

6 Lay Out a GUIDE GUIthe selected components. Look for the highlight as described in “Add aComponent to a Panel or Button Group” on page 6-34.Front-to

Seite 109 - Command-Line Accessibility

Add Components to the GUI• Send to Back — Move the selected object(s) behind n onse lecte d objects(available from the right-click context menu, the L

Seite 110 - Ha ndle Visibility and

6 Lay Out a GUIDE GUIIf you drag or resize the component, the readout updates accordingly. Thereadout to the left of the component position readout di

Seite 111 - OpeningFcn, which can

Add Components to the GUIUse Arrow Keys to Move ComponentsSelect one or more components that you w ant to move, then press and holdthe arrow keys unti

Seite 112 - Generate FIG-File Only

How to Contact MathWorkswww.mathworks.comWebcomp.soft-sys.matlab Newsgroupwww.mathworks.com/contact_TS.html Technical [email protected] Pro

Seite 114 - Callbac k property of

6 Lay Out a GUIDE GUI2 Click the + sign next to Position. The Property Inspector displays theelements of thePosition property.3 If you have selected•

Seite 115 - Lay Out a GUIDE GUI

Add Components to the GUIDrag a Corner of the ComponentSelect the component you want to resize. Click one of the corner handles anddrag it until the c

Seite 116 - Design a GUI

6 Lay Out a GUIDE GUI2 Click the + sign next to Position. The Property Inspector displays theelements of thePosition property.3 Type the width and hei

Seite 117 - Design a G UI

Align ComponentsAlign ComponentsIn this section...“Align O bjects Tool” on page 6 -89“Property Inspector” on page 6-92“Grid a nd Rulers ” on page 6-96

Seite 118 - Star t GUIDE

6 Lay Out a GUIDE GUITheAlignObjectstoolprovidestwotypesofalignmentoperations:• Align — Align all selected components to a single reference line.• Dis

Seite 119 - Start GUIDE

Align ComponentsAlign OptionsThere are both vertical and horizontal align options. E ach option alignsselected components to a reference line, which i

Seite 120 - Select a GUI Template

6 Lay Out a GUIDE GUIBoth modes enable you to specify how the spacing is measured, as indicatedby the button labels on the alignment tool. These optio

Seite 121 - Template Descriptions

Align ComponentsScroll down to see additional properties. C lick any property value or icon totheleftofonetosetitsvalue,eitherdirectlyinthatfieldorvia

Seite 122 - 6 Lay Out a GUIDE GUI

6 Lay Out a GUIDE GUIThe Property Inspector provides context-sensitive help for individualproperties. Right-clicking a property nam e or value opens a

Seite 123 - GUI with Uicontrols

Align Components2 Select Property Inspector from the View menu or click the PropertyInspector button.3 In the Property Inspector, scroll to the Units

Seite 124

1About GUIs in MATLABSoftware• “What Is a G U I?” on page 1-2• “How Does a GUI W ork?” on page 1-4• “Where Do I Start?” on page 1-6• “Ways to Build MA

Seite 125

6 Lay Out a GUIDE GUIGrid and RulersThe layout area displays a grid a nd rulers to facilitate component layout.Grid lines are spaced at 50-pixel inter

Seite 126

Align ComponentsCreating Guide LinesTo create a guide line, click the top or left ruler and drag the line into thelayout area.6-97

Seite 127 - Modal Question Dialog

6 Lay Out a GUIDE GUISet Tab OrderA GUI’s tab order is the order in which com ponents of the GUI acquire focuswhen a user presses the Tab key on the k

Seite 128 - WindowStyle property

Set Tab OrderThe figure in the following GUI contains an axes component, a slider, a panel,static text, and a pop-up menu. Of these, only the slider,

Seite 129 - Click and drag

6 Lay Out a GUIDE GUITo examine and change the tab order of the panel components, click the panelbackground to select it, then select Tab Order Editor

Seite 130

Create Menus in a GUIDE GUICreate Menus in a GUIDE GUIIn this section...“Menus for the Menu Bar” on page 6-102“Context Menus” on page 6-114You can use

Seite 131

6 Lay Out a GUIDE GUINoteSee “Menu Item” on page 8-59 and “Updating a Menu Item C heck” onpage8-61 for info rm ation abou t progra m m i n g and basic

Seite 132

Create Menus in a GUIDE GUI• “CreateaMenu”onpage6-106• “Add Items to a Menu” on page 6-109• “Additional Drop-Down M enus” on page 6-111• “Cascading Me

Seite 133 - Add Components to the GUI

6 Lay Out a GUIDE GUIThe WindowStyle figure property also affects docking behavior. The default is'normal', but if you change it to 'do

Seite 134

Create Menus in a GUIDE GUIIn either case, you can enable u sers of your GUI to dock and undock it usingits docking arrow by setting the figure’sDockC

Seite 135

1 About GUIs in MATLAB®SoftwareWhat Is a GUI?A graphical user interface (G UI) is a graphical display in one or morewindows containing controls, calle

Seite 136

6 Lay Out a GUIDE GUICreate a Menu1 Start a new menu b y clicking the New Menu button in the toolbar. A menutitle,Untitled 1, appears in the left pane

Seite 137

Create Menus in a GUIDE GUI2 Click the menu title to display a selection of menu properties in the rightpane.3 Fill in the Label and Tag fields for th

Seite 138

6 Lay Out a GUIDE GUIremove, default,andfactor y (case sensitive) are reserved. To use oneof these as labels, prepend a backslash (\) to the string. F

Seite 139

Create Menus in a GUIDE GUIAdd Items to a MenuUse the New Menu Item tool to create menu items that are displayed inthe drop-down menu.1 Add an Open me

Seite 140

6 Lay Out a GUIDE GUI2 Fill in the Label and Tag fields for the new menu item . For example, setLabel toOpen and set Tag to menu_file_open. Click outs

Seite 141

Create Menus in a GUIDE GUIsome accelerators may be used for other purposes on your system and thatother actions may result.• Di splay a sepa rator ab

Seite 142

6 Lay Out a GUIDE GUICascading MenusTocreateacascadingmenu,selectthemenuitemthatwillbethetitleforthecascading menu, then click the New Menu Item butto

Seite 143

Create Menus in a GUIDE GUINote See “Menu Item” on page 8-59 for information about programmingmenu items.The following Menu Editor illustration shows

Seite 144

6 Lay Out a GUIDE GUIContext MenusA co ntext menu is displayed w he n a user right-clicks the object for which themenuisdefined. TheMenuEditorenablesy

Seite 145

Create Menus in a GUIDE GUI1 Select the Menu Editor’s Context Menus tab and select the New ContextMenu button from the toolbar.6-115

Seite 146

What Is a GUI?• Three buttons that provide different kinds of plots: surface, mesh, andcontourWhen you click a push button, the axes component display

Seite 147

6 Lay Out a GUIDE GUI2 Select the menu and specify the Tag field to identify the context m enu(axes_context_menu in this example).Add Items to the Con

Seite 148

Create Menus in a GUIDE GUI6-117

Seite 149 - Highlight

6 Lay Out a GUIDE GUI2 Fill in the Label and Tag fields for the new menu item . For example, setLabel toBlue background color and set Tag to blue_back

Seite 150

Create Menus in a GUIDE GUIopened. If you clear this option, the menu item appears dimmed when themenu is first opened, and the user cannot select it.

Seite 151

6 Lay Out a GUIDE GUIThe View button displays the callback, if there is one, in an editor. If youhave not yet saved the GUI, GUIDE prompts you to save

Seite 152

Create Menus in a GUIDE GUINote See “Menu Item” on page 8-59 and “Updating a Menu Item C heck” onpage 8-61 for programming information and basic examp

Seite 153 - Commonly Used Properties

6 Lay Out a GUIDE GUICreate ToolbarsIn this section...“Create Toolbars with GUIDE” on page 6-122“Editing Tool Icons” on page 6-131Create Toolbars with

Seite 154

Create ToolbarsThe Toolbar Editor gives you interactive access to all the features of theuitoolbar, uipushtoo l,andu itoggletool functions. It only op

Seite 155

6 Lay Out a GUIDE GUINote You do not need to use the Toolbar Editor if you simply want your GUIto have a standard figure toolbar. You can do this by s

Seite 156

Create ToolbarsTo add a tool, drag an icon from the Tool Palette into the Toolbar Layout(which initially contains the text prompt shown above), and e

Seite 157 - Radio Button

1 About GUIs in MATLAB®SoftwareHow Does a GUI Work?In the GUI described in “W hat Is a GUI?” on page 1-2, the user selects a dataset from the pop-up m

Seite 158

6 Lay Out a GUIDE GUIWhen you f irst create a GUI, no toolbar exists on it. When you open theToolbar E ditor and place the first tool, a toolbar is cr

Seite 159 - Check Box

Create ToolbarsPredefined and Custom ToolsThe Toolbar E ditor provides two types of tools :6-127

Seite 160

6 Lay Out a GUIDE GUI• Predefined tools, having standard icons and behaviors• Custom tools, having generic icons and n o b ehaviorsPredefined Tools. T

Seite 161

Create ToolbarsMove ToolsYou can reorder tools on the toolbar in two ways:• Drag a tool to a new position.• Select a tool in the toolbar and click one

Seite 162

6 Lay Out a GUIDE GUISee “Working with Callbacks in G UIDE” on page 8-2 for details onprogramming the tool callbacks. You can also access these and ot

Seite 163

Create ToolbarsRemove a ToolbarYou can remove a toolbar completely— destroying it— from the Toolbar Editor,leaving your GUI without a toolbar (other t

Seite 164

6 Lay Out a GUIDE GUINote There are examples that show how to create your own icon e ditor. Seethe example in “Icon Editor” on page 15-63 and the disc

Seite 165

Create ToolbarsUse the I con EditorThe Icon Editor G UI includes the following components:• Icon file name —Theiconimagefiletobeloadedforediting• Impo

Seite 166 - String property to

6 Lay Out a GUIDE GUI• Ho ld down the left mouse button an d drag the mous e over the grid totransfer the selected color to the squares that you touch

Seite 167

Create Toolbars6-135

Seite 168

How Does a GUI Work?running at those times. This distinguishes event-driven programming fromother types of control flow, for example, processing seque

Seite 169

6 Lay Out a GUIDE GUIView the Object HierarchyThe O bject Browser displays a hierarchical list of the objects in the figure,including both components

Seite 170

Designing for Cross-Platform CompatibilityDesigning for Cross-Platform CompatibilityIn this section...“Default System Font” on page 6-137“Standard Bac

Seite 171 - Position

6 Lay Out a GUIDE GUISpecify a Fixed-Width FontIf you w ant to use a fixed-width font for a user interface control, set itsFontName property to the st

Seite 172

Designing for Cross-Platform CompatibilityThe following figures illustrate the results with and without system colormatching.Cross-Platform Compatible

Seite 173 - \remove yields remove

6 Lay Out a GUIDE GUIUnits and Resize BehaviorIf you set your GUI’s resize behavior from the GUI Options dialog box,GUIDE automatically sets the units

Seite 174 - My Button Group

7Save and Run a GUIDEGUI• “NameaGUIandItsFiles”onpage7-2• “Save a G U IDE GUI” on page 7-4• “Run a GUIDE GUI” on page 7-10

Seite 175

7 Save and Run a GUIDE GUINameaGUIandItsFilesIn this section...“The GUI Files” on page 7-2“File and GUI Names” on page 7-3“Rename GUIs and GUI Files”

Seite 176

NameaGUIandItsFilesFor more information about these files, see “Files Generated by GUIDE”on page 8-7.File and GUI NamesThecodefileandtheFIG-filethatde

Seite 177

7 Save and Run a GUIDE GUISave a GUIDE GUIIn this section...“Ways to Save a GUI” on page 7-4“Save a New GUI” on page 7-5“SaveanExistingGUI”onpage7-8“E

Seite 178

Save a GUIDE GUIIn either case, GUIDE prompts you for a name before saving the GUI,and saves both a.fig file and a .m file using the name you specify,

Seite 179

1 About GUIs in MATLAB®SoftwareWhere Do I Start?Before starting to construct a GUI you have to design it. At a minimum,youhavetodecide:• Who the GUI u

Seite 180 - NextPlot property has its

7 Save and Run a GUIDE GUINote If you select Save as from the File menu or click the Save buttonon the toolbar, GUID E saves the GUI without activatin

Seite 181 - Creating a Table

Save a GUIDE GUI4 If you choo se a n e xisting filen ame, GUIDE di splays a dialog bo x th at asksyou i f you want to replace the existing FIG-file. C

Seite 182

7 Save and Run a GUIDE GUI6 If you chose to activate the GUI by selecting Run fro m the Tools menuor by clicking the Run buttonon the toolbar, and if

Seite 183

Save a GUIDE GUIIf you select Save from the File menu or click the Save button on thetoolbar, GUIDE saves the GUI without activating it.ExportaGUIDEGU

Seite 184

7 Save and Run a GUIDE GUIRun a GUIDE GUIIn this section...“Execute GUI Code” on page 7-10“From the GUIDE Layout Editor” on page 7-10“From the Command

Seite 185 - ColumnEditable

Run a GUIDE GUIIn either case, if the GUI has changed or has never been saved, GUID E savesthe GUI files before activating it and opens the GUI code f

Seite 186

7 Save and Run a GUIDE GUIThe GUI files must reside on the MATLAB path or in the current MATLABfolder where the GUI is run.If a GUI accepts arguments

Seite 187

Run a GUIDE GUIfor val = 1:3set(handles.plot_popup,'Value',val)simple_gui('plot_popup_Callback',...handles.plot_popup,[],handles)%

Seite 188 - RowName, Show

7 Save and Run a GUIDE GUI7-14

Seite 189

8Programming a GUIDEGUI• “Working with Callbacks in GUIDE” on page 8-2• “Files Generated by GUIDE” on page 8-7• “Default Callback Properties in GUIDE”

Seite 190

Where Do I Start?UnderstandRequirements Purpose Use cases Interactivity FunctionalitySpecify GUI(s) Inputs Controls Displays Behavior Outputs

Seite 191 - Add ActiveX Controls

8 Programming a GUIDE GUIWorking with Callbacks in GUIDEIn this section...“Programming GUIs Created Using GUIDE” on page 8-2“What Is a Callback?” on p

Seite 192

Working with Callbacks in GUIDEof that component. For example, a push button has five callback properties:ButtonDownFcn, Callback, CreateFcn, DeleteFc

Seite 193

8 Programming a GUIDE GUICallback Property Triggering Event ComponentsCreateFcnInitializes the componentwhen a function createsit. It executes after t

Seite 194

Working with Callbacks in GUIDECallback Property Triggering Event ComponentsSelectionChangeFcnExecutes when a GUI userselects a different radiobutton

Seite 195

8 Programming a GUIDE GUINote User interface controls include push buttons, sliders, radio buttons,check boxes, editable text boxes, st atic text boxe

Seite 196

Files Generated by GUIDEFiles Generated by GUIDEIn this section...“Code Files and FIG-Files” on page 8-7“GUI Code File Structure” on page 8-8“Adding C

Seite 197 - Locate and Move Components

8 Programming a GUIDE GUIFor more information, see “Name a GUI and Its Files” on page 7-2,“Save aGUIDE GUI” on page 7-4, and“Re name G UIs an d GU I F

Seite 198

Files Generated by GUIDEAdding CallbackTemplates to an Existing GUI CodeFileWhen you save theGUI, GUIDE automatically adds templates for somecallbacks

Seite 199

8 Programming a GUIDE GUIGUIDE names callbacks based on the callback type and the componentTag property. For example, togglebutton1_Callb ack is such

Seite 200

Default Callback Properties in GUIDEDefault Callback Properties in GUIDEIn this section...“Setting Callback Properties Automatically” on page 8-11“Del

Seite 201

1 About GUIs in MATLAB®SoftwareWays to Build MATLAB GUIsA M ATLAB GUI is a figure window to which you add user-operated controls.You can select, size,

Seite 202

8 Programming a GUIDE GUIThe following figure shows properties of a push button in the GUID EProperty Inspector prior to saving the GUI. GUIDE set the

Seite 203 - Align Components

Default Callback Properties in GUIDEWhen you save the GUI, GUIDE constructs the name of the callback byappending an underscore (_) and the name o f th

Seite 204

8 Programming a GUIDE GUIWhen you save th e GUI, GUIDE also o pens the GUI code file in y ou r e di tor.The file then contains a template for theCallb

Seite 205 - Align Options

Customizing Callbacks in GUIDECustomizing Callbacks in GUIDEIn this section...“GUIDE Callback Templates” on page 8-15“Callback Names and Signatures in

Seite 206

8 Programming a GUIDE GUI% Modifier: name(s) of the modifier key(s) (i.e., control, shift)% pressed% handles structure with handles and user data (see

Seite 207 - Extent,andPosition

Customizing Callbacks in GUIDEproperty for the push button, and Callback is one of the push button’s callbackproperties. TheTag property uniquely iden

Seite 208

8 Programming a GUIDE GUI@(hObject,eventdata)mygui('pushbutton1_Callback',hObject,eventdata,guidata(hObject))The syntax @(hObject,eventdata)

Seite 209

Customizing Callbacks in GUIDE@(hObject,eventdata)mygui('pushbutton1_Callback',hObject,eventdata,guidata(hObject))Saving a GUI with a push b

Seite 210

8 Programming a GUIDE GUIGUIDE Callback ArgumentsAll callbacks ina GUIDE-generated GUI code file have the following standardinput arguments:•hObject —

Seite 211 - Creating Guide Lines

Customizing Callbacks in GUIDE• KeyP ress Fcn in uicontrols and figures•KeyReleaseFcn in a figure•SelectionChangeFcn in a uibuttongroup•WindowKeyPress

Seite 212 - Set Tab Order

Ways to Build MATLAB®GUIsType of GUI TechniqueDialog boxMATLAB software provides aselection of standard dialog boxesthat you can create with a singlef

Seite 213

8 Programming a GUIDE GUIthe programmatic uitable example “GUI that Dis plays a nd Graphs TabularData” on page 15-19.handles StructureGUIDE creates a

Seite 214

Customizing Callbacks in GUIDEwarnbeforesave. If possible, change the Tag property before saving the GUIto cause GUIDE to autom atically create callba

Seite 215 - Create Menus in a GUIDE GUI

8 Programming a GUIDE GUIClick Yes to revert to the GUID E auto-generated callback. click No to keepthe modified callback.Note Remember to change the

Seite 216

Initialize a GUIDE GUIInitialize a GUIDE GUIIn this section...“Opening Function” on page 8-25“Output F unction” on page 8-28Opening FunctionThe openin

Seite 217

8 Programming a GUIDE GUI% Update handles structureguidata(hObject, h andles);% UIWAIT makes mygui wait for user response (see UIRESUME)% uiwait(handl

Seite 218

Initialize a GUIDE GUIGUI template, available from the GUIDE Quick Start dialog box. The addedcode opens the modal dialog w ith a message, specified f

Seite 219

8 Programming a GUIDE GUI...The if block loops through the odd elements of varargi n checking forproperty names or aliases, and thecase blocks assign

Seite 220

Initialize a GUIDE GUIFunction Naming and TemplateGUIDE names the output function b y appending _OutputFcn tothenameofthe G UI. This is an example of

Seite 221

8 Programming a GUIDE GUIAdd Code for Components in CallbacksIn this section...“Push B utton” on page 8-30“Toggle Button” on page 8-31“Radio Button” o

Seite 222

Add Code for Components in C allbacksThis is the push button’s Callback callback. It displays the string Goodbye atthe command line and then closes th

Seite 223 - Untitled,appears

Revision HistoryNovember 2000 Online Only New for MATLAB 6.0 (Release 12)June 2001 Online Only Revised for MATLAB 6.1 (Release 12.1)July 2002 Online O

Seite 224

1 About GUIs in MATLAB®Software1-10

Seite 225 - Edit drop-down menu

8 Programming a GUIDE GUIbutton_state = get(hObject,'Value');if button_st ate == get(hObject,'Max')% Toggle button is pressed, tak

Seite 226 - Copy is a cascading menu

Add Code for Components in C allbacksselects the radio button with Tag property radiobutton1 and deselects thepreviously selected radio button.Note Yo

Seite 227

8 Programming a GUIDE GUIIf the edit text Max and Min properties are set such that Max - Min > 1,theuser can enter m ultiple lines. For example, se

Seite 228

Add Code for Components in C allbacksAvailable Keyboard AcceleratorsGUI users can use the following keyboard accelerators to modify the contentof an e

Seite 229 - Menu button from the toolbar

8 Programming a GUIDE GUITable CellSelectionCallbackEverytimetheuserselectsatablecell,thetable’sCellSelectionCallbackfires. This happens whether table

Seite 230

Add Code for Components in C allbacksselects the second item in the list box w ith Tag property listbox1.Triggering Callback ExecutionMATLAB software

Seite 231

8 Programming a GUIDE GUIUsing Only the Index of the Selected Menu ItemThis example retrieves only the index of the item selected. It uses a switchsta

Seite 232

Add Code for Components in C allbacksgroups as well as axes and u ser interface controls such as push buttons,sliders, pop-up menus, etc. The position

Seite 233

8 Programming a GUIDE GUI2 Create callbacks for the two push buttons, and place the follow ing line ofcode in each of them.set(gcbf,'Position&apo

Seite 234 - Tag property axes1

Add Code for Components in C allbacksset(buttons(1),'FontSize',newFontSi ze); % Resize the first button% Do not resize the other button for

Seite 235

2How to Create a G UI withGUIDE• “Introduction to GUIDE” on page 2-2• “Abo ut the Simple GUIDE GU I Example” on page 2-9• “Lay Out the Simple GUI in G

Seite 236 - Create Toolbars

8 Programming a GUIDE GUITip You can enable text in controls to resize automatically by setting thecomponent’sfontUnits to normalized, without the nee

Seite 237

Add Code for Components in C allbacksIf a user clicks the other radio button or one of the toggle buttons, it becomesselected and Radio B utton 1 is d

Seite 238

8 Programming a GUIDE GUI• Select SelectionChangeFcn from the View > View C allbacks submenu,or• Right-click and select SelectionChangeFcn from the

Seite 239

Add Code for Components in C allbacksAxesAxes components enable your GUI to display graphics, such as graphs andimages. This topic briefly tells you h

Seite 240

8 Programming a GUIDE GUI1 Add this code to the Plot 1 push button’s Callback callback. The surffunction produces a 3-D shaded surface plot. The peaks

Seite 241 - Predefined and Custom Tools

Add Code for Components in C allbacksNote For information about properties that you can set to control manyaspects of axes behavior and appearance, se

Seite 242

8 Programming a GUIDE GUITip When working with multiple axes, it is best not to “raise” the axes y ouwant to plot data into with commands likeaxes(a1)

Seite 243 - Edit a Tool’s Properties

Add Code for Components in C allbacksFor more information about subplots, see the subplot reference page. Forinformation about adding panels to your G

Seite 244

8 Programming a GUIDE GUINote The following links execute MATLAB commands and are designed towork w ithin the MATLAB Help brow ser. If you are reading

Seite 245 - EditingToolIcons

Add Code for Components in C allbacksNote Clicking Create places a copy of the file Mwsamp_activex1 in yourworking folder. If you move your GUI files

Seite 246

2 How to Create a GUI with GUIDEIntroduction to GUIDEIn this section...“What Is GUIDE?” on page 2-2“Opening G U IDE ” on page 2-2“Getting Help in GUID

Seite 247 - Use the I con Editor

8 Programming a GUIDE GUIpane. The following figure shows the ActiveX control as it appears in theLayout Editor.If you need help adding the component,

Seite 248

Add Code for Components in C allbacks5 View the ActiveX Properties with the Property Inspector. Select the controlin the Layout Editor, and then selec

Seite 249

8 Programming a GUIDE GUI7 Add the following code to the mswamp control’s active x1_Click callback.This code programs the ActiveX control to change th

Seite 250 - View the Object Hierarchy

Add Code for Components in C allbacksProgramming a User Interface Control to Update an ActiveXControlThis topic continues the previous example by addi

Seite 251 - Default System Font

8 Programming a GUIDE GUIViewing the Methods for an ActiveX ControlTo view the available methods for an ActiveX control, you first need to obtainthe h

Seite 252 - FixedWidthFontName property

Add Code for Components in C allbacksAlternatively, you can entermethods(hObject)which displays the available methods in the MATLAB Command Window.For

Seite 253 - Units of pixels does not

8 Programming a GUIDE GUICompiling a GUI That Contains an ActiveX ControlIf you use the MATLAB Compiler mcc command to compile a GUI thatcontains an A

Seite 254

Add Code for Components in C allbacksMenu ItemThe G UIDE M enu Editor generates an empty callback subfunction for everymenu item, including menu title

Seite 255 - Save and Run a GUIDE

8 Programming a GUIDE GUIMouse Gestures and Menu Callback Behavior. Callback s for leaf me n uitems, such as for to file or to clipboard in the previo

Seite 256 - NameaGUIandItsFiles

Add Code for Components in C allbacksUpdating a Menu Item CheckA check is useful to indicate the current state of some menu items. If youselected Chec

Seite 257 - Rename GUIs and GUI Files

Introduction to GUIDEWhen you right-click a FIG-file in this way, the figure opens in the GUIDELayout Editor, where you can work on it.2-3

Seite 258 - Save a GUIDE GUI

8 Programming a GUIDE GUI8-62

Seite 259 - Save a New GUI

9Managing and SharingApplication Data in GUIDE• “Ways to Manage Data in a GUIDE GUI” on page 9-2• “Making Multiple GUIs Work Together” on page 9-21

Seite 260 - 7 Save and Run a GUIDE GUI

9 Managing and Sh aring Application Data in GUIDEWays to Manage Data in a GUIDE GUIIn this section...“Data Management Mechanism Summary” on page 9-2“N

Seite 261 - Tag properties do not

Ways to Manage Data in a GUIDE GUIData-SharingMethodHow it WorksUse for...Pass function handlesor data through oneof the four followingmethods:Exposin

Seite 262

9 Managing and Sh aring Application Data in GUIDE• Nested Functions — Share variables defined at a higher level and callone another when called functi

Seite 263 - UserData)

Ways to Manage Data in a GUIDE GUIUserData PropertyAll GUI components, including menus and the figure itse lf have a UserDataproperty. Y ou can assign

Seite 264 - Run a GUIDE GUI

9 Managing and Sh aring Application Data in GUIDEOnly Handle Graphics MATLAB objects use this property. The following tablesummarizes the functions th

Seite 265 - From Any MATLAB Code File

Ways to Manage Data in a GUIDE GUIAdding Fields to an Application Data Structure in GUIDEApplication data is usually defined as a structure. This enab

Seite 266

9 Managing and Sh aring Application Data in GUIDE• GUI d ata is a single variable; how ever, when defined as a structure, youcan add and remove fields

Seite 267

Ways to Manage Data in a GUIDE GUIadds the field number_errors to the ha ndle s structure and sets it to 0.2 Use the following com mand to save the da

Seite 268

2 How to Create a GUI with GUIDEAll tools in the tool palette have tool tips. Setting a GUIDE preference letsyou display the palette in GUIDE with too

Seite 269 - Programming a GUIDE

9 Managing and Sh aring Application Data in GUIDEmeans while it is currently running, its internal state might not need to beinitialized again. One wa

Seite 270 - 8 Programming a GUIDE GUI

Ways to Manage Data in a GUIDE GUIIf the user types a number between 0 and 1 in the edit text componentand then presses Enter or clicks outside the ed

Seite 271

9 Managing and Sh aring Application Data in GUIDE1 Click here to copy the files to your current folder.2 Type guide slider box_ userdata or click here

Seite 272

Ways to Manage Data in a GUIDE GUIThis section shows you h ow to use GUI data to initialize and maintain anerror counter by storing an error count in

Seite 273

9 Managing and Sh aring Application Data in GUIDEset(hObject,'UserData',data);% Display new total.set(hObject,'String',...['Y

Seite 274

Ways to Manage Data in a GUIDE GUI2 Type guide slide rbox _appdata or click here to open the GUI in GUIDE.3 Type edit sliderbox_appdata orclickheretoo

Seite 275 - Files Generated by GUIDE

9 Managing and Sh aring Application Data in GUIDEThe section “Sharing Data with GUI Data” on page 9-17 uses GUI data toinitialize and maintain an erro

Seite 276

Ways to Manage Data in a GUIDE GUIslider_data = getappdata(handles.figure1,'slider');slider_data.number_errors = sli der_data.number_errors+

Seite 277 - Adding Callback

9 Managing and Sh aring Application Data in GUIDE3 edit sli derb ox_guidata or click here to open the GUI code file in theEditor.You can view the prop

Seite 278 - Tag,GUIDErenamesallits

Ways to Manage Data in a GUIDE GUI• When a user types a value into the edit text component, the slider updatesto this value.• If a user enters a value

Seite 279

Introduction to GUIDEThe first three options lead you to topics in the GUIDE documentation thatcan help you get started using GUIDE. The Example GUIs

Seite 280 - Tag property

9 Managing and Sh aring Application Data in GUIDE• The set command sets the String property of the edit text to theupdated value.3 Set the slider valu

Seite 281

Making Multiple GUIs Work TogetherMaking Multiple GUIs Work TogetherIn this section...“Data-Sharing Techniques” on page 9-21“Example — Manipulating a

Seite 282

9 Managing and Sh aring Application Data in GUIDEExample — Manipulating a Modal Dialog Box forUser Input• “View and Run the changeme GUI” on page 9-23

Seite 283 - GUIDE Callback Templates

Making Multiple GUIs Work TogetherNote The changeme_dialog GUI is patterned after the MATLAB inpu tdlgfunction, a predefined dialog box that serves th

Seite 284

9 Managing and Sh aring Application Data in GUIDEYou can view the properties of any component by double-clicking it in theLayout Editor to open the Pr

Seite 285 - Callback Function Signatures

Making Multiple GUIs Work Togetherchangeme_dialog('changeme_main', handles.figure);ThedialogboxusesthehandletoaccessthemainGUI’sdata. Ifthem

Seite 286

9 Managing and Sh aring Application Data in GUIDE...uiresume(handles.figure);Protecting and Positioning the Text Change Dialog1 The user opens the Tex

Seite 287 - GUIDE-generated callbacks

Making Multiple GUIs Work Togetherdisp('------------------------------ ----------------------- ');disp('Improper input arguments. Pass

Seite 288

9 Managing and Sh aring Application Data in GUIDEset(hObject, 'Position', [newX, newY, newW, newH]) ;...Initializing Text in the Text Change

Seite 289

Making Multiple GUIs Work Togetheruiresume(handles.figure);function fig ure_ CloseRequestFcn(hObject , ...eventdata, ha ndle s)uiresume(hObject);Apply

Seite 290

2 How to Create a GUI with GUIDEType of VideoVideo ContentMATLAB New FeatureDemosNew Graphics and GUI Building Features inVersion 7.6 (9 min, 31 s)New

Seite 291

9 Managing and Sh aring Application Data in GUIDEwait state; if it is, it ca lls uiresum e and returns, enabling the OutputFcnto be called:function fi

Seite 292

Making Multiple GUIs Work TogetherThese GUIs share data and expose functionality to one another using severaldifferent techniques:9-31

Seite 293 - Initialize a GUIDE GUI

9 Managing and Sh aring Application Data in GUIDEView and Run the Three Icon Manipulation GUIsIf you are reading this in the M ATLAB Help browser, you

Seite 294

Making Multiple GUIs Work TogetherNote Do n o t save GUI files to the examples folder where you fo und them,or you will overwrite the original files.

Seite 295

9 Managing and Sh aring Application Data in GUIDEguide_iconeditor_OpeningFcn(hObject, eventdata, handles, varargin)varargout = guide_iconeditor_Output

Seite 296

Making Multiple GUIs Work TogethertoolPicker_CreateFcn(hObject, eventdata, handles)toolPalette_SelectionChangeFcn(hObject, eventdata, ha ndles)figure_

Seite 297 - Output Arguments

9 Managing and Sh aring Application Data in GUIDE...% Update handles structureguidata(hObject, h andles);The Color Palette nee ds to remember the Icon

Seite 298

Making Multiple GUIs Work Together...% Update handles structureguidata(hObject, h andles);Setting the Initial Color on the Color PaletteAfter you crea

Seite 299 - Toggle Button

9 Managing and Sh aring Application Data in GUIDEhandles.mSelectedColor =color;...guidata(hObject, handles);Call the publicized function from the Icon

Seite 300

Making Multiple GUIs Work Together..% Update handles structureguidata(hObject, handles);The Icon Editor retrieves the initial color from the Color Pal

Seite 301 - Edit Text

Introduction to GUIDEAuthors add new tutorials to the set over time. Bo okmark this page andrevisit it occasionally to see them.Laying Out a GUIDE GUI

Seite 302

9 Managing and Sh aring Application Data in GUIDEguidata(hObject, handles);When you select the pencil tool and click in the icon-editing area, the Ico

Seite 303 - Cell Sele ctionCallback

Making Multiple GUIs Work Together...rows = size(handles.mIconCData, 1);cols = size(handles.mIconCData, 2);pt = get(handles.icon,'currentp oint&a

Seite 304

9 Managing and Sh aring Application Data in GUIDEYou cannot close the Co lo r Pale tte and Tool P a lette windows by directlyclicking their close butt

Seite 305 - Pop-Up Menu

Making Multiple GUIs Work Togetherfunction fig ure_ CloseRequestFcn(hObject , eventdata, handle s)% Don't close this figure. It must be dele ted

Seite 306

9 Managing and Sh aring Application Data in GUIDE9-44

Seite 307

10Examples of GUIDE GUIs• “GUI with Multiple Axes (GUIDE)” on page 10-2• “GUI for Animating a 3-D View (GUIDE)” on page 10-15• “GUI to Interactively E

Seite 308

10 Examples of GUIDE GUIsGUI with Multiple Axes (GUIDE)In this section...“About the Multiple Axes Example” on page 10-2“View and Run the M u ltip l e

Seite 309

GUI with Multiple Axes (GUIDE)Note You can create a more adv anced GUI that also displays time andfrequency plots by following the GUIDE example “GUI

Seite 310

10 Examples of GUIDE GUIs1 Click here to copy the files to your current folder.2 Type guide two_axes or click here to open the GUI in GU IDE.3 Type ed

Seite 311 - Programming a Button Group

GUI with Multiple Axes (GUIDE)• Frequency two (f2)• Atimevector(t)When the user clicks the Plot button, the GUI puts these values into aMATLAB express

Seite 312

2 How to Create a GUI with GUIDE• Create menus and context menus• Create toolbars• Modify the appearance of components• Set tab order• View a hierarch

Seite 313 - Callback

10 Examples of GUIDE GUIsTo create the default values, set the String property of the edit text. Thefollowing figure shows the value set for the time

Seite 314

GUI with Multiple Axes (GUIDE)The structure contains handles for all G UI components. You access thehandles using field names that GUIDE derives from

Seite 315 - Creating Subplots

10 Examples of GUIDE GUIsGUI Option SettingsGUIDE has a set of preferences called GUI Options, available from the Toolsmenu. Two GUI Options settings

Seite 316

GUI with Multiple Axes (GUIDE)• Evaluating the time string using eval to produce a vector t,whichthecallback used to evaluate the mathematical expres

Seite 317 - ActiveX Control

10 Examples of GUIDE GUIs• Providing the appropriate data to the plot function• Turning on the axes grid, w hich theplot function automatically turns

Seite 318

GUI with Multiple Axes (GUIDE)Validate User Input as NumbersGUI u sers type parameters into three edit text boxes as strings of text. Ifthey type an i

Seite 319 - Mwsamp_activex1 in your

10 Examples of GUIDE GUIsif isnan(f1) || ~isreal(f1)% isdouble returns NaN for non-numbers and f1 cannot be complex% Disable the Plot button and chang

Seite 320

GUI with Multiple Axes (GUIDE)%tisnotanumberset(handles.plot_button,'String','t is not numeric')elseif length(t) < 2%tisnotavec

Seite 321 - 5 View the Ac

10 Examples of GUIDE GUIsIn this figure, the two p lots reflect the last successful set of inputs, f1 =31.41, f2 = 120,andt=[1234579].Thetimevector[12

Seite 322

GUI for Animating a 3-D View (GUIDE)GUI for Anim ating a 3-D View (GUIDE)In this section...“About the 3-D Animation Example” on page 10-15“ViewandRunt

Seite 323

About the S imple GUIDE GUI ExampleAbout the Simple GUIDE GUI ExampleIn this section...“Simple G UIDE GUI Components” on page 2-9“View Simple GUIDE GU

Seite 324

10 Examples of GUIDE GUIs• Start and stop the rotation.• Change lighting direction.• Display a latitude-longitude grid (or graticule).• Save the anima

Seite 325

GUI for Animating a 3-D View (GUIDE)the figure, the code, or both. Then you can save the G UI in your currentfolder using File > Save as from GUIDE

Seite 326

10 Examples of GUIDE GUIs• Static textThe Property Inspector was used to custom ize the uicontrols and text by:• Setting the figureColor to black, as

Seite 327 - Menu Item

GUI for Animating a 3-D View (GUIDE)The GUI includes three uipanels that you can barely see in this figure becausethey are entirely black. Using uipan

Seite 328

10 Examples of GUIDE GUIsThe Show grid check box toggles the Visible property of the graticulesurface object. Theaxes1_CreateFcn initializes the grati

Seite 329 - Updating a Menu Item Check

GUI for Animating a 3-D View (GUIDE)FunctionFunction Behaviorsunazslider_CreateFcnInitializes light source azimut hslider (not customized)sunelslider_

Seite 330

10 Examples of GUIDE GUIsstr = get(hObject,'String');state = find(strcmp(str,handles .Strings));set(hObject,'String',handles.Strin

Seite 331 - Application Data in GUIDE

GUI for Animating a 3-D View (GUIDE)example d oes not explore the technique, but you can find information aboutprogramming timers in “Using a MATLA B

Seite 332

10 Examples of GUIDE GUIsThe file name of the movie ends with the number o f frames it contains.Supposing the m ovie’s file name isglobe360.mat,youpla

Seite 333

GUI for Animating a 3-D View (GUIDE)• “Create the Graphic Objects” on page 10-25• “Texture and Color the Globe” on page 10-26• “Plot the Graticule” on

Seite 335 - Application Data

2 How to Create a GUI with GUIDETo use the GUI, select a data set from the pop-up menu, then click one of theplot-type buttons. Clicking the button tr

Seite 336

10 Examples of GUIDE GUIsTexture and Color the GlobeCode in the ax es1_CreateFcn sets the CData for the globe to the 180-by-360(one degree)topo terrai

Seite 337 - GUI Data

GUI for Animating a 3-D View (GUIDE)ThestateoftheShow grid button is initially off, causing the graticule notto display. Show grid toggles the mesh ob

Seite 338 - GUI Data in GUIDE

10 Examples of GUIDE GUIsset(hgrotate,'Matrix',makehgtform(' zrotate',az));drawnow % Refresh the screenLight the Globe and Shift t

Seite 339

GUI for Animating a 3-D View (GUIDE)Further GraphicExplorationsYou can enhance the pre sentation ofglobegui in various ways, including:• Adding a colo

Seite 340 - Introduction

10 Examples of GUIDE GUIsTip Use a spherical grid that is the same size as topo to add terrain reliefto the globe. Then scale the values oftopo to wel

Seite 341 - Sharing Data with UserData

GUI to Interactively Explore Data in a Table (GUIDE)GUI to Interactively Explore Data in a Table (GUIDE)In this section...“About the tablestat Example

Seite 342

10 Examples of GUIDE GUIs• Plots that portray periodicity in the entire data set and in selections of it.• Context menus for the axes that let the use

Seite 343

GUI to Interactively Explore Data in a Table (GUIDE)Note The tablestat example is based on the MATLAB sunspots demoand data set. Click here to view th

Seite 344

10 Examples of GUIDE GUIsNote Do not save GUI files to the examp les folder where you found themor you will overwrite the original files. If you want

Seite 345

GUI to Interactively Explore Data in a Table (GUIDE)Function NameFunction BehaviorGUIDE-Generated?plotPeriodGenerates plots (either time series orperi

Seite 346

Lay Out the Simple GUI in GUIDELay Out the Simple GUI in GUIDEIn this section...“Open a New GUI in the GUIDE Layout Editor” on page 2-11“Set the GU I

Seite 347 - Sharing Data with GUI Data

10 Examples of GUIDE GUIsPerform the following steps in GUIDE and in the P roperty Inspector togenerate the layout, thereby creating the follow ing ob

Seite 348

GUI to Interactively Explore Data in a Table (GUIDE)• A panel on the low er right, half the height of the first panel, renamingitsTitle to Data Statis

Seite 349

10 Examples of GUIDE GUIsb In the Property Inspector, click the Table Property Editor icon tothe right of theRowName property to open the Table Proper

Seite 350

GUI to Interactively Explore Data in a Table (GUIDE)5 Drag out a second axes, leaving its name as axes2 inside the Sunsp ots v.Year Plots pane l, dire

Seite 351 - Data-Sharing Techniques

10 Examples of GUIDE GUIs• Double-click it and in the Property Inspector, set its Tag property to quitand its String property to Quit.• Click theCallb

Seite 352 - User Input

GUI to Interactively Explore Data in a Table (GUIDE)6 From the list of workspace variables in the box below the radio button,selectsunspot and click O

Seite 353

10 Examples of GUIDE GUIsif ~isempty( peak )stats{9,col} = peak; % Peak period from FFTendNote When assigning data to a uitable, use a cell array, as

Seite 354

GUI to Interactively Explore Data in a Table (GUIDE)function plot_t ype_ Callback(hObject, e vent data, handles)% hObject handle to plot_type (see GCB

Seite 355

10 Examples of GUIDE GUIsRespond to Data SelectionsThe DataSettable has two columns: Year and Sunspots. The data tables’sCell Selection Callback analy

Seite 356

GUI to Interactively Explore Data in a Table (GUIDE)discontiguous rows to a selection. Because the Cell Sele ction Callback istriggered as long as the

Seite 357

2 How to Create a GUI with GUIDE2 In the GUIDE Quick Start dialog box, select the Blank GUI (Default)template. Click OK to display the blank GUI in th

Seite 358

10 Examples of GUIDE GUIsThis vector enumerates all the selected row s. If the selection includes lessthan 11 rows (as it does h ere) the callback ret

Seite 359 - Closing the Main GUI

GUI to Interactively Explore Data in a Table (GUIDE)updates the Data Statistics table with the recomputed statistics. Here is thecode forrefreshDispla

Seite 360 - Icon Manipulation Tools

10 Examples of GUIDE GUIs3 Resizing the new axes to use 90% of the figure’s width.4 Constructing a title string and displaying it in the new figure.5

Seite 361

GUI to Interactively Explore Data in a Table (GUIDE)7 Click OK to save your menus and exit the Menu Editor.For more information about using the Menu E

Seite 362

10 Examples of GUIDE GUIs% we want to do anything else to themhandles.axes1fig = axes1fig;handles.axes1copy = axes1copy;guidata(hObject,handles);The o

Seite 363 - Icon Editor Implementation

GUI to Interactively Explore Data in a Table (GUIDE)Upon Clicking Open plot in new window, a new figure is displayed withthe following content.10-51

Seite 364 - • guid e_to olPalatte.m

10 Examples of GUIDE GUIsIt is the user’s responsibility to remove the new window when it is no longerneeded. The context menus can be programmed to d

Seite 365

GUI to Interactively Explore Data in a Table (GUIDE)- Provide a file dialog box or an input dialog box and code capable offiltering out nonnumeric, no

Seite 366

10 Examples of GUIDE GUIsList Box Directory Reader (GUIDE)In this section...“About the List Box Directory Example” on page 10-54“View and Run the L is

Seite 367 - % Update handles structure

List Box Director y Reader (GUIDE)View and Run the List Box Directory GUIIf you are reading this document in the MATLAB Help browser, you canaccess th

Seite 368

Lay Out the Simple GUI in GUIDE3 Display the names of the GUI components in the component palette. SelectFile > Preferences. Then select GUIDE >

Seite 369

10 Examples of GUIDE GUIsNote Do not save GUI files to the examp les folder where you found themor you will overwrite the original files. If you want

Seite 370

List Box Director y Reader (GUIDE)% hObject handle to figure% eventdata reserved - to be defined in a future v ersion of MATLAB% handles structure wit

Seite 371

10 Examples of GUIDE GUIs• Use the dir command to get a list of files in the specified folder and todetermine which name is a folder and which is a fi

Seite 372

List Box Director y Reader (GUIDE)is a file, it is passed to the open command; if it is a folder, the GUI changesto that folder and lists its contents

Seite 373

10 Examples of GUIDE GUIsfile_list = get(handles.listbox1,' String');% Item selected in list boxfilename = file_list{index_selecte d};% If f

Seite 374

Access Workspace Variables from a List Box (GUIDE)Access Workspace Variables from a List Box (GUIDE)In this section...“About the Workspace Variable Ex

Seite 375

10 Examples of GUIDE GUIsView and Run the Workspace Variable GUIIf you are reading this document in the M ATLAB Help browser, you canaccess the exam p

Seite 376 - 10 Examples of GUIDE GUIs

Access Workspace Variables from a List Box (GUIDE)To just inspect the GUI in GUIDE and run it, follow these steps instead:1 Clickheretoaddtheexamplefi

Seite 377

10 Examples of GUIDE GUIsRead Selections from List BoxTheGUIrequirestheusertoselecttwovariablesfromtheworkspaceandthen choose one of three plot comman

Seite 378

Access Workspace Variables from a List Box (GUIDE)list_entries = get(handles.listbox1,'String');index_selected = get(handles.listbox1,'

Seite 379

2 How to Create a GUI with GUIDESet the GUI FigureSizeinGUIDESet the size of the GUI by resizing the grid area in the Layout Editor. Clickthe lower-ri

Seite 380

10 Examples of GUIDE GUIsA GUI to Set Simulink Model Parameters (GUIDE)In this section...“About the Simulink Model Parameters Example” on page 10-66“V

Seite 381

A GUI to Set Simulink®Model Parameters (GUIDE)The e xample illustrates a number of GUI building techniques:• Opening and setting parameters on a Simul

Seite 382

10 Examples of GUIDE GUIs2 Type guide f14ex or click here to open the FIG-file in G UID E.3 Type edit f1 4ex or click here to op en th e code file in

Seite 383 - Plot Data

A GUI to Set Simulink®Model Parameters (GUIDE)F14 Controller Gain EditorYou can use the F14 Controller Gain Editor to analyze how changing thegains us

Seite 384

10 Examples of GUIDE GUIsThe graph is displayed in a figure, which is cleared e ach time you click thePlot button. The figure’s handle is hidden so th

Seite 385

A GUI to Set Simulink®Model Parameters (GUIDE)• Bring t he GUI forwa rd so it is display e d on t op of the Simulink diagrams(figure).• Set the block

Seite 386

10 Examples of GUIDE GUIs• Sets the value of the Current value edit text component to match theslider.• Sets the appropriate block parameter to the ne

Seite 387

A GUI to Set Simulink®Model Parameters (GUIDE)If the value is in range, the slide r Value property is updated to the newvalue.• Sets the appropriate b

Seite 388

10 Examples of GUIDE GUIs• Creates a structure to save the results of the simulation, the currentvalues of the simulation parameters set by the GUI, a

Seite 389

A GUI to Set Simulink®Model Parameters (GUIDE)if isequal(R esul tNum,1)ResultsStr = {['Run1',num2str(Kf), ' ',num2str(Ki)]};elseRe

Seite 390

Lay Out the Simple GUI in GUIDEAdd Components totheSimpleGUIDEGUI1 Add the three push buttons to the GUI. Select the push button tool fromthe componen

Seite 391 - Designthe3-DGlobeGUI

10 Examples of GUIDE GUIsif isequal(numResu lts,length(currentVal)),resultsStr = {'<empty>'};currentVal = 1;set([handles.RemoveButton,

Seite 392

A GUI to Set Simulink®Model Parameters (GUIDE)• Create an axes, set its Paren t property to the figure handle, and save theaxes handle.• Create the pl

Seite 393

10 Examples of GUIDE GUIsend% Plot datapHandles = plot(PlotData{:},'Parent',handles.PlotAxes);% Add a legend, and bring figure to the frontl

Seite 394

A GUI to Set Simulink®Model Parameters (GUIDE)function CloseB utto n_Callback(hObject, eventdata, handles)% Close the GUI and any plot window that is

Seite 395

10 Examples of GUIDE GUIsSet the Background to WhiteThe list box create function enables you to determine the background colorof the list box. The fol

Seite 396

An Address Book Reader (GUIDE)An Address Book Reader (GUIDE)In this section...“About the A ddress B ook Reader Example” on page 10-81“View and Run the

Seite 397 - Make a Movie of the Animation

10 Examples of GUIDE GUIsThe example demonstrates the following GUI programm ing techniques:• Uses open and save dialog boxes to provide a means for u

Seite 398

An Address Book Reader (GUIDE)1 Click here to copy the files to your current folder.2 Type guide addr ess_ book orclickheretoopentheFIG-fileinGUIDE.3

Seite 399 - Create the Graphic Objects

10 Examples of GUIDE GUIs• Com mand-line accessib ility: Off• GUI O ptions selecte d:- Generate callback function prototypes- Application allows only

Seite 400

An Address Book Reader (GUIDE)% Load the default address boo kCheck_And_Load([],handles);% If the fi rst element in vara rgi n is 'book' and

Seite 401 - Visible property

2 How to Create a GUI with GUIDEArrange the components as shown in the following figure. Resize the axescomponent to approximately 2-by-2 inches.Align

Seite 402

10 Examples of GUIDE GUIs• Returns 1 for valid M AT-files and 0 if invalid (used by the Open menucallback).• Saves the following items in thehandles s

Seite 403 - Explorations

An Address Book Reader (GUIDE)end% If the file is valid, display itif pass% Add Addresses to the handles structurehandles.Addresses = data.Addresses;g

Seite 404

10 Examples of GUIDE GUIsFile = fullfile(pathname,filename) ;% if the M AT-f ile is not valid, do not save the nameif Check_And_Lo ad(F ile,handles)ha

Seite 405 - About the tablestat Example

An Address Book Reader (GUIDE)Contact Name Callbackfunction Contac t_Na me_Callback(hObject, eventdata, handles)% Get the strings in the Contact Name

Seite 406

10 Examples of GUIDE GUIs)set(handles.Contact_Phone,'String', Addresses(handles.Index) .Phone)returnendThe Contact Phone Number CallbackThe

Seite 407

An Address Book Reader (GUIDE)handles.Addresses = Addresses;guidata(hObject, handles)returncase 'Cancel '% Revert back to the original numbe

Seite 408

10 Examples of GUIDE GUIsis used in case statements to implem ent each button’s functionality (seethe code listing that follows).Paging Forward or Bac

Seite 409 - Design the tablestat GUI

An Address Book Reader (GUIDE)Current_Phone = Addresses(i).Phone;set(handles.Contact_Name,'string',C urrent_Name)set(handles.Contact_Phone,&

Seite 410 - Tag properties (which are

10 Examples of GUIDE GUIsSave_Callback Code Listingfunction Save_C allb ack(hObject, eventd ata, handles)% Get the Tag of the menu selectedTag = get(h

Seite 411

An Address Book Reader (GUIDE)The Address BookResize FunctionThe address bookdefines its own resize function. To use this resize function,you must set

Seite 412

Lay Out the Simple GUI in GUIDE3 Make these settings in the Alignment Tool, as shown in the following figure:• Left-aligned in the horizontal directio

Seite 413

10 Examples of GUIDE GUIsChange the HeightThe height a nd width of the figure is specified in pix el units. Usin g unitsof pixels enables maximizing a

Seite 414

An Address Book Reader (GUIDE)returnend% If resized figure is smal ler than original f igure then compensa te% However, do not change figure size if i

Seite 415 - Compute the Data Statistics

10 Examples of GUIDE GUIsUse a Modal Dialog Box to Con firm an Operation (GUIDE)In this section...“About the Modal Dialog Example” on page 10-98“View

Seite 416

Use a Modal Dialog Box to C onfirm an Operation (GUIDE)figure property WindowStyle determines whether it is modal or not. TypingCtrl+C changes a'

Seite 417

10 Examples of GUIDE GUIs2 ClickheretorunthemodalGUIs.3 ClickheretodisplaytheGUIsintheGUIDE Layout Editor (read only).4 Click here to display the GUI

Seite 418

Use a Modal Dialog Box to C onfirm an Operation (GUIDE)The GUI looks like the following figure.Note Modal dialog bo x es (figures with WindowStyle set

Seite 419

10 Examples of GUIDE GUIs8 Click the Show functions icon on the toolbar of the editor and selectclose_pushbutton_Callback from the drop-down menu.The

Seite 420

Use a Modal Dialog Box to C onfirm an Operation (GUIDE)When you click the Close button on the GUI, the m odal dialog box opens, asshown in the followi

Seite 421

10 Examples of GUIDE GUIsThis is an example of calling a GUI with a property value pair. In thiscase, the figure property is'Title', and its

Seite 422

Time Data Updates from a GUI (GUIDE)Time Data Updates from a GUI (GUIDE)In this section...“About the Timer GUI Example” on page 10-105“View and Run th

Seite 423

2 How to Create a GUI with GUIDE4 Click OK. You r GUI n ow looks like this in the Layout Editor.Add Text to the ComponentsThe p ush buttons, p op-up m

Seite 424

10 Examples of GUIDE GUIsView and Run the GUIDE Timer GUIThis example contains link s to a FIG-file and a code file that MA TLABdocumentation provides

Seite 425

Time Data Updates from a GUI (GUIDE)2 Type guide ex_guide_timergui in the C ommand Window or click hereto open the GUI in GUIDE.3 Open the G UI co de

Seite 426

10 Examples of GUIDE GUIsthe link in the Callback column. You cannot access the timer object fromwithin GUIDE; it is created programmatically.Componen

Seite 427

Time Data Updates from a GUI (GUIDE)How the GUI Implements the TimerEach callback inthe G UI either creates, m odifies, starts, stops, or destroysthe

Seite 428

10 Examples of GUIDE GUIsstartbtn_Callbackstartbtn_Callback calls timer start m ethod if the timer is not alreadyrunning:if strcmp(get(h andl es.timer

Seite 429 - View and Run the L

Time Data Updates from a GUI (GUIDE)update_displayupdate_display is the callback for the timer object. It adds Gaussian noise totheZData ofthesurfacep

Seite 430

10 Examples of GUIDE GUIsOther Uses for Timers in GUIsIn addition to acquiring or processing data at regular intervals, you can usetimers to implement

Seite 431 - Load the List Box

Create GUIs ProgrammaticallyChapter 11, Lay Out aProgrammatic GUI (p. 11-1)Shows you how to createand organize the GU I codefile and from there how to

Seite 433

11Lay Out a ProgrammaticGUI• “Design a Programmatic GUI” on page 11-2• “Create and Run a Programmatic GUI” on page 11-4• “Create Figures for Program m

Seite 434

Lay Out the Simple GUI in GUIDEAfter you have added the appropriate text, the GUI will look like this in theLayout Editor.Label the Push Buttons. Each

Seite 435

11 Lay Out a Programmatic GUIDesign a Programmatic GUIBefore creating the actual GUI, it is important to decide what it is you wantyour GUI to do and

Seite 436

Design a Programmatic GUIMany Web sites and commercial publications such as th e followin g provid eguidel ines for design ing GUIs:• AskTog — Essays

Seite 437 - Read Workspace Variables

11 Lay Out a Programmatic GUICreateandRunaProgrammaticGUIIn this section...“File Organization” on page 11-4“File Template” on page 11-4“Run the GUI” o

Seite 438

CreateandRunaProgrammaticGUI% to the help co mman d.% (Leave a blank line follo wing the help.)% Initialization tasks% Construct th e components% Init

Seite 439

11 Lay Out a Programmatic GUICreate Figures for Programmatic GUIsIn MATLAB software, a GUI is a figure. B efore you add components to it,create the fi

Seite 440

Create Figures for Programmatic GUIsProperty Values DescriptionResizeon, off.Defaultison. Determines if the user canresize the figure window w iththe

Seite 441 - Model Parameters (GUIDE)

11 Lay Out a Programmatic GUIThe Position property is a four-element vecto r that spe cifies the location ofthe GUI on the screen and its size: [dista

Seite 442

Add Components to a Programmatic GUIAdd Components to a Programmatic GUIIn this section...“Types of G UI Components” on page 11-9“Add User Interface C

Seite 443 - Kf)intheGainblock

11 Lay Out a Programmatic GUIComponent Function DescriptionActiveXactxcontrolActiveX components enable you todisplay ActiveX controls in yourGUI. They

Seite 444

Add Components to a Programmatic GUIComponent Function Description“Panel” on page11-35uipanelPanels arrange GUI components intogroups. By vis ually gr

Seite 445 - Slider Callback

ContentsIntroduction to Creating GUIsAbout GUIs in MATLAB S oftware1What Is a GUI? ... 1-2How Does a GUI Work?...

Seite 446

2 How to Create a GUI with GUIDE2 In the layout area, select the top push button by clicking it.3 In the Property Inspector, select the String propert

Seite 447

11 Lay Out a Programmatic GUIComponent Function Description“Slider” on page11-28uicontrolSliders accept numeric input withina specified range by enabl

Seite 448

Add Components to a Programmatic GUIComponent Function Descriptiongrouptomanagemutuallyexclusiveradio buttons.Toolbar Buttonsuitoolbar,uitoggletool,ui

Seite 449 - Remove Results from List Box

11 Lay Out a Programmatic GUI• “Check Box” on page 11-15• “Edit Text” on page 11-17• “List Box” on page 11-20• “Pop-Up Menu” on page 11-22• “Table” on

Seite 450

Add Components to a Programmatic GUIProperty Values DescriptionStringString. C an be a cellarray or character array orstrings.Component label. For lis

Seite 451 - Plot Button Callback Listing

11 Lay Out a Programmatic GUIcbh = uicontrol(fh,'Style','checkb ox',...'String','Display file extension ',...&

Seite 452

Add Components to a Programmatic GUINote You can also use an image as a label. See “Add an Image to a PushButton” on page 11-26 for more information.E

Seite 453

11 Lay Out a Programmatic GUIIf Max-Min is less than or equal to 1, the edit text component admits only asingle line ofinput. If you specify a com po

Seite 454

Add Components to a Programmatic GUIfont =FontName: 'Century Schoolbook'FontWeight: 'normal'FontAngle: 'normal'FontSize:

Seite 455

11 Lay Out a Programmatic GUIInstead of d esignating a font yourself, you could provide a push button orcontext menu in your GUI that allows users to

Seite 456

Add Components to a Programmatic GUIString PropertyFormatExampleCell array of strings{'one' 'two' 'three'}Padded s tring

Seite 457 - GUI Option Settings

Lay Out the Simple GUI in GUIDE5 Select each of the remaining push buttons in turn and repeat steps 3 and 4.Label the middle push button Mesh, and the

Seite 458

11 Lay Out a Programmatic GUIIf the list box is not large enough to display all list entries, you can set theListBoxTop property to the index of the i

Seite 459 - Validate the MAT-file

Add Components to a Programmatic GUIThe Str ing property defines the menu items. You can specify the items inany of the formats shown in the following

Seite 460 - - The Address es structure

11 Lay Out a Programmatic GUITableThe following code creates a table with handle th. It populates it with thematrixmagic(5), and then adjusts its size

Seite 461 - Open_Callback Code Listing

Add Components to a Programmatic GUI• Foreground and background colors.• Row striping.• Row labels/numbers.• Column labels/numbers.• Column formats an

Seite 462

11 Lay Out a Programmatic GUIThe Style property, pushbutton, specifies the user interface control as a pushbutton. Becausepushbutton is the default st

Seite 463 - Contact Name Callback

Add Components to a Programmatic GUINote Create your own i con with the icon editor described in “Icon Editor”on page 15-63. Seeind2rgb for informatio

Seite 464

11 Lay Out a Programmatic GUIThe Value property specifies w hether the radio button is selected when thecomponent is created. SetValue to the value of

Seite 465

Add Components to a Programmatic GUI• Specify the value indicated by the slider when it is created by setting theValue property to the appropriate num

Seite 466

11 Lay Out a Programmatic GUINote On Mac p latforms, the height of a horizo ntal s lide r is co n strained. Ifthe height you set in the position vecto

Seite 467 - Save the MAT-File

Add Components to a Programmatic GUIThe Position property specifies the lo cation and size of the static textcomponent. In this exam ple, the static t

Seite 468

2 How to Create a GUI with GUIDE3 Replace the existing text with the names of the three data sets: Peaks,Membrane, and Sinc. Press Enter to move to th

Seite 469 - Resize Function

11 Lay Out a Programmatic GUIaccommodate the s pe cified String, MATLAB software truncates the stringwith an ellipsis.The Value property specifies whe

Seite 470

Add Components to a Programmatic GUIAsyntaxforpanelsisph = uipanel(fh,'PropertyName',Pro pertyValue,...)where ph is the handle of the result

Seite 471

11 Lay Out a Programmatic GUIProperty Values DescriptionParentHandleHandle of the component’s parentfigure, panel, or button group.Position4-element v

Seite 472

Add Components to a Programmatic GUIPanelThe following statement creates a panel w ith handle ph.Useapaneltogroupcomponents in the GUI.ph = uipanel(&a

Seite 473

11 Lay Out a Programmatic GUIfigure and 10 percent of the figure height from the bottom. As the figure isresized the panel retains these proportions.T

Seite 474

Add Components to a Programmatic GUIThe Parentproperty specifies the handle fh of the parent figure. You can alsospecify the parent as a panel o r but

Seite 475

11 Lay Out a Programmatic GUI'Position',[.1 .6 .3 .2]);rbh2 = uicontrol(bgh,'Style','r adiobutton','String',&a

Seite 476

Add Components to a Programmatic GUI• “Axes” on page 11-39Commonly Used PropertiesThe most commonly used properties n eeded to describe an axes are sh

Seite 477 - Close-Confirmation GUIs Work

11 Lay Out a Programmatic GUIah = axes('Parent',fh,'Position',[ .15 .15 .7 .7]);The Parent property specifies the handle fh of the

Seite 478

Add Components to a Programmatic GUIThe s oftware automatically adds the tick marks. Most functions that drawin the axes u pdate the tick marks approp

Seite 479 - About the Timer GUI Example

Lay Out the Simple GUI in GUIDE3 Click OK .ThephraseSelect Data appears in the static text componentabove the pop-up menu.Completed Simple GUIDE GUI L

Seite 480

11 Lay Out a Programmatic GUICompose and Code GUIs with Interactive ToolsIn this section...“Set Positions of Components Interactively” on page 11-43“A

Seite 481

Compose and Code GUIs with Interactive ToolsSome of thes e tools return property valu e s, while others let you edit propertiesinteractively without r

Seite 482

11 Lay Out a Programmatic GUI4 Make sure that you know the handle of the component you havemanipulated. In the following code, the handle is a variabl

Seite 483 - How the GUI Imple

Compose and Code GUIs with Interactive Toolsrect = get(handle,'Position');inspect(handle)To experiment with the function, enter the followin

Seite 484

11 Lay Out a Programmatic GUIUsePlotEditModetoChangePropertiesAfter you select an object in plot edit mode, you can open the PropertyInspector to view

Seite 485

Compose and Code GUIs with Interactive ToolsScroll in the help window to view descriptions of other properties. Click the Xclose box to close the w in

Seite 486

11 Lay Out a Programmatic GUIshows the Backgrou ndCo lor and S tring properties of a list box altered usingthe Property Editor.Most of the properties

Seite 487

Compose and Code GUIs with Interactive ToolsYou can obtain the new property value by running the ge t function:value = get(object_handle, 'Proper

Seite 488

11 Lay Out a Programmatic GUIset(object_handle,'Position',rect)set(object_handle,'Units',myunits)elserect = [];endclipboard('

Seite 489 - Lay Out a Programmatic

Compose and Code GUIs with Interactive Tools3 Release the mouse button. The control moves.4 The button Position is set, returned and placed on the sys

Seite 490 - Design a Programmatic GUI

2 How to Create a GUI with GUIDE2-24

Seite 491

11 Lay Out a Programmatic GUIbtn1 = uicontrol('Style','pushbutt on',...'String','Push Me','Position'

Seite 492 - CreateandRunaProgrammaticGUI

Compose and Code GUIs with Interactive Tools5 Place your cursor between the empty brackets and type Ctrl+V,orright-click and select Paste. Allowing fo

Seite 493 - Run the GUI

11 Lay Out a Programmatic GUIalso distribute the components evenly across their span or specify a fixeddistance between them.A syntax for thealign fun

Seite 494 - 11 Lay Out a Programmatic GUI

Compose and Code GUIs with Interactive ToolsNote Each of the three following align examples starts with these unalignedpush buttons and repositions th

Seite 495

11 Lay Out a Programmatic GUIAlign Com ponents Vertically W hile Distributing Them Ho rizontally.The following statement moves the push buttons to the

Seite 496

Compose and Code GUIs with Interactive ToolsUseAlignDistributeToolsIf your figure has a standard menu bar, y ou can perform align and distributeoperat

Seite 497 - TypesofGUIComponents

11 Lay Out a Programmatic GUIThe following steps illustrate how to use the Align Distribute tool to arrangecomponents in a GUI. The tool provides the

Seite 498

Compose and Code GUIs with Interactive ToolsThe buttons align as shown.Note One thing to remember w hen aligning components is that the alig nfunction

Seite 499

11 Lay Out a Programmatic GUIFor more information, see “Ali gn/Distribute Menu Optio ns”.Set Colors InteractivelySpecifying colors for Color, Foregrou

Seite 500

Compose and Code GUIs with Interactive Toolsof colors. The uisetcolor function opens a GUI that returns color valuesyou can plug into components when

Seite 501

Save the GUI LayoutSave the GUI LayoutWhen you save a GUI, GUIDE creates two files, a FIG-file and a code file. TheFIG-file, with extension.fig, is a

Seite 502

11 Lay Out a Programmatic GUISet Font Characteristics InteractivelyThe uisetfont GUI gives you access to the characteristics of all fonts on yoursyste

Seite 503

Compose and Code GUIs with Interactive Tools'String',inputdlg('String','Static Text'),...uisetfont,'Position',

Seite 504

11 Lay Out a Programmatic GUIGenerate Code to Set Component PropertiesThe techniques described in the preceding s ections set properties ofcomponents

Seite 505

Compose and Code GUIs with Interactive ToolsHelp system that contains doc examples. See “View and Run the setpropFunction” on page 11-68. Property val

Seite 506

11 Lay Out a Programmatic GUIfor the current value of the property, or '' for an invalidproperty nam e.setstr = setprop(objhandle,prop erty,

Seite 507

Compose and Code GUIs with Interactive Toolssetprop(object_handle,'pos')ans =set(object_handle,'Position',[20 20 60 20])If you omi

Seite 508

11 Lay Out a Programmatic GUITip You can provide an empty property name followed by a value when youcallsetprop. Then, the function attempts to assign

Seite 509

Compose and Code GUIs with Interactive Tools1 Click here to add all GUI example files to the M ATLAB path (only for thecurrent session).2 Type edit se

Seite 510

11 Lay Out a Programmatic GUISet Tab Order in a Programmatic GUIIn this section...“How Tabbing Works” on page 11-70“Default Tab O rder” on page 11-70“

Seite 511

Set Tab Order in a Programmatic GUI'String',{'peaks','membrane','sinc'},. ..'Position',[290 200 130

Seite 512

2 How to Create a GUI with GUIDE4 Browse to any folder for which you have write privileges, and then enterthe filenamesimple_gui for the FIG-file. GUI

Seite 513 - Push Button

11 Lay Out a Programmatic GUIwhere ph is the handle of the panel. This statement returns a vectorcontaining the handles of the children, the three pus

Seite 514

Set Tab Order in a Programmatic GUIChange the Tab OrderUse the uist ack function to change the tab order of components that have thesame parent. A con

Seite 515

11 Lay Out a Programmatic GUINote Tab order also affects the stacking order of components. If componentsoverlap, those that appear low er in the child

Seite 516

Create Menus for a Programmatic GUICreate Menus for a Programmatic GUIIn this section...“Add Menu Bar Menus” on page 11-75“Add Context Menus to a Prog

Seite 517 - (major_step)

11 Lay Out a Programmatic GUIIf you use the standard menu bar menus, any menus you create are added toit. If you choose not to display the standard me

Seite 518

Create Menus for a Programmatic GUIProperty Values DescriptionHandleVisibilityon, off. Default ison.Determines if an object’s handleis visible in its

Seite 519

11 Lay Out a Programmatic GUIFigure windows with a standard menu bar also have a Desktop menu fromwhich the user can dock and undock them.To display t

Seite 520

Create Menus for a Programmatic GUIMenu Bar MenuThe following statements create a menu bar menu with two menu items.mh = uimenu(fh,'Label',&

Seite 521

11 Lay Out a Programmatic GUIThe following statement adds a separator line preceding the second menuitem.set(eh2,'Separator','on')

Seite 522

Create Menus for a Programmatic GUINote After you have created all menu items, set their HandleVisibilityproperties off by executing the following sta

Seite 523

Save the GUI LayoutTo run a GUI created with G UID E without opening GUIDE, execute its codefile by typing its name.simple_guiYou can also use the run

Seite 524

11 Lay Out a Programmatic GUIProperty Values DescriptionHandleVisibilityon, off. Default ison.Determines if an object’s handle is visible inits parent

Seite 525

Create Menus for a Programmatic GUIfh = figure('Position',[300 300 400 225]);cmenu = uicontextmenu('Parent', fh,'Position&apo

Seite 526

11 Lay Out a Programmatic GUIYou can use any applicable Uimenu Properties such as C heck ed or Separatorwhen you define context menu items. See the ui

Seite 527

Create Menus for a Programmatic GUIThis code associates the context menu with the figure and with the axes bysetting theUIContextMenu property of the

Seite 528

11 Lay Out a Programmatic GUIRight-click on the figure or on the axes. The context menu appears with itsupper-left corner at the location you clicked.

Seite 529

Create Menus for a Programmatic GUIThe context menu is displayed 10 pixels from the left of the figure and 215pixels from the bottom.If you set the co

Seite 530

11 Lay Out a Programmatic GUICreate Toolbars for Programmatic GUIsIn this section...“Use the u itoolbar Function” on page 11-88“Commonly Used Properti

Seite 531 - Color or

Create Toolbars for Programmatic GUIsProperty Values DescriptionCData3-D array of valuesbetween 0.0 and 1.0n-by-m-by-3 array o f RGBvalues that define

Seite 532

11 Lay Out a Programmatic GUIimg1(:,:,1) = repmat(a,16,1)'img1(:,:,2) = repmat(a,16,1);img1(:,:,3) = repmat(flipdim(a,2),16,1);pth = uipushtool(t

Seite 533

Create Toolbars for Programmatic GUIsTooltipString specifies the tooltips for the push tool and the toggle too l asMy push tool and Your toggle tool,r

Seite 534

2 How to Create a GUI with GUIDEProgram the Simple GUIDE GUIIn this section...“Add Code to the Simple GUIDE GUI” on page 2-28“Generate Data to Plot” o

Seite 535

11 Lay Out a Programmatic GUINote After you have created a toolbar and its tools, set theirHandleVisibility properties of f by executing statements si

Seite 536

Create Toolbars for Programmatic GUIsModify the Standard ToolbarOnce you have the handle of the standard toolbar, you can add tools, deletetools, and

Seite 537 - Sketch a Position Vector

11 Lay Out a Programmatic GUIDesign Programmatic GUIs for Cross-PlatformCompatibilityIn this section...“Default System Font” on page 11-94“Standard Ba

Seite 538

Design Programmatic GUIs for Cross-Platform CompatibilityUse a Specific Font NameYou can specify an actual font name (such as Times or Courier) for th

Seite 539

11 Lay Out a Programmatic GUIThe following figures illustrate the results with and without system colormatching.Cross-Platform Compatible UnitsCross-p

Seite 540

Design Programmatic GUIs for Cross-Platform CompatibilityResizeFcn enables you to customize the GUI’s resize behavior and is validonly if you setResiz

Seite 541

11 Lay Out a Programmatic GUINorm alized. Normalized units represent a percentage of the size of theparent. The value of normalized units lies between

Seite 542

12Code a Programmatic G UI• “Organize a Programmatic GUI File” on page 12-2• “Initialize a Programmatic GUI” on page 12-3• “Write Code for Callbacks”

Seite 543

12 Code a Programmatic GUIOr ganize a Programmatic GUI FileAfter laying out your GUI, program its behavior. This chapter addresses theprogramming of G

Seite 544

Initialize a Programmatic GUIInitialize a Programmatic GUIWhen you open a GUI, it usually initializes certain data structures andvariable values. Thes

Seite 545 - UseAlignDistributeTools

Program the Simple GUIDE GUIThe cursor moves to the opening function, which already contains this code:% --- Executes just before simple_gui is made v

Seite 546 - HorizontalAlignment

12 Code a Programmatic GUIExamplesIf you are reading this in the MATLAB Help Browser, use the following linksto view the complete code files for th e

Seite 547

Initialize a Programmatic GUIThe fullfi le function builds a full filename fr om parts.The following statements each start the Icon Editor. The first

Seite 548

12 Code a Programmatic GUIMost components have Visible properties. You can also use these propertiesto make individual components invisible.Return Out

Seite 549

WriteCodeforCallbacksWrite Code for CallbacksIn this section...“What Is a Callback?” on page 12-7“Kinds of Callbacks” on page 12-8“Specify Callbacks i

Seite 550

12 Code a Programmatic GUIKindsofCallbacksThe GUI figure and each type of component has specific kinds of callbackswith which you can associate it. Th

Seite 551

WriteCodeforCallbacksCallback Property Triggering Event ComponentsClickedCallbackControl action. Executeswhen the push tool ortoggle tool is clicked.

Seite 552

12 Code a Programmatic GUICallback Property Triggering Event ComponentsResizeFcnExecutes when a userresizes a panel, buttongroup, or figure whosefigur

Seite 553

WriteCodeforCallbacksNote User interface controls include push buttons, sliders, radio buttons,check boxes, editable text boxes, st atic text boxes, l

Seite 554

12 Code a Programmatic GUIYou can attach a callback when you create a component by supplying thecallback’s property name and value (its calling sequen

Seite 555

WriteCodeforCallbacksYou can concatenate commands in a string callback. This one, for example,adds a title to the plot it creates.set(hb,'Callbac

Seite 556

Save the GUI Layout ... 2-25Program the Simple GUIDE GUI... 2-28Add Code to the Simple GUIDE GUI...

Seite 557

2 How to Create a GUI with GUIDE% uiwait(handles.f igure1);2 Create data for the GUI to plot by adding the following code to the openingfunction immed

Seite 558

12 Code a Programmatic GUIfunction displa y_sl ider_value(hObject,even tdata)disp(['Slider moved to ' num2str(get(hObject,'Valu e'

Seite 559

WriteCodeforCallbacksthat you specify. Place single quotes around the function name and any literalstring arguments, but not around workspace variable

Seite 560

12 Code a Programmatic GUIfunction pushbu tton _callback(hObject, eventdata, var1, va r2)plot(var1,var2)When you run this GUI by pressing the push but

Seite 561 - Change the Tab Or

WriteCodeforCallbacksUse Cell Arrays with Function Handles. You can specify a callbackfunction using a function handle instead of using a function nam

Seite 562

12 Code a Programmatic GUINote Unless you declare them as string s (with required arguments, asdescribed in “Use String Callbacks” on page 12-12), do

Seite 563 - Add Menu Bar Menus

WriteCodeforCallbacksGUI ComponentCallbacks with EventDataProperty ReferencePagesFigureKeyPressFcn,KeyReleaseFcn,WindowKeyPressFcn,WindowKeyReleaseFcn

Seite 564

12 Code a Programmatic GUIExamples: Program GUI ComponentsIn this section...“Program User Interface Controls” on page 12-20“Program Panels and Button

Seite 565

Examples: Program GUI C omponentsCheck BoxYou can determine the current state of a check box from within any of itscallbacks by querying the state of

Seite 566

12 Code a Programmatic GUIRetrieve Numeric Data from an Edit Text Component. MATLA Bsoftware returns the value of the edit textString property as a ch

Seite 567 - Menu Bar Menu

Examples: Program GUI C omponents• Ctrl+V –Paste• Ctrl+H – Delete last character• Ctrl+A – Select allList BoxWhen the list box Callback callback is tr

Seite 568

Program the Simple GUIDE GUIProgram the Pop-Up MenuThe pop-up menu enables the user to select the data to plot. When the GUIuser selects one of the th

Seite 569

12 Code a Programmatic GUIopen on the second click. The callback can query the figure Sel ectionTypeproperty to determine if it was a single or d oubl

Seite 570

Examples: Program GUI C omponentsYou can also select a menu item programm atically by setting the pop-upmenuValue property to the index o f the desire

Seite 571

12 Code a Programmatic GUIclose(gcbf)gcbfreturns the handle of the figure containing the object whose callbackis executing.Radio ButtonYou can determi

Seite 572

Examples: Program GUI C omponentsslider_value = get(hObject,'Value');% Proceed with callback...The Max an d Min properties specify the slide

Seite 573

12 Code a Programmatic GUINote You can use a button group to m anage exclusive selection behavior fortoggle buttons. See “B utton Group” on page 12-28

Seite 574 - Position property is

Examples: Program GUI C omponentsset of radio buttons, toggle buttons, or both, the button group allows only oneof them to be selected. When a user cl

Seite 575

12 Code a Programmatic GUIThe button group Sele ctionChangeFcn callback is called whenever a selectionis made. If you have a button group that contain

Seite 576

Examples: Program GUI C omponentsProgram AxesAxes components enable your GUI to display graphics, such as graphs andimages. This topic briefly tells y

Seite 577 - Toolbars

12 Code a Programmatic GUI2 Run the GUI by typing two_axes at the command line. This is what theexample looks like before you click the push buttons.3

Seite 578

Examples: Program GUI C omponentsSee “GUI with Multiple Axes (GUIDE)” on page 10-2 for a more complexexample that uses two axes.If your GUI contains a

Seite 579

2 How to Create a GUI with GUIDEIf the editor is not already open, GUIDE opens it to display the GUIcode file, and the cursor moves to the pop-menu ca

Seite 580

12 Code a Programmatic GUI• Properties that you can set to control many aspects of axes behavior andappearance, see “Axes Objects — Defining Coordinat

Seite 581 - Modify the Standard Toolbar

Examples: Program GUI C omponentsWhen a user selects Edit > Copy > to file,noCopy callback is needed toperform the action. Only theCallback call

Seite 582 - Compatibility

12 Code a Programmatic GUIOpen a Dialog Box from a Menu CallbackThe Callback callback for the to file menu item could contain code such asthe followin

Seite 583 - Standard Background Color

Examples: Program GUI C omponentsUse of checks when the GUI is first displayed should be consistent with thedisplay. For example, if your GUI has an a

Seite 584

12 Code a Programmatic GUI2 Click the push tool to display the color selection dialog box and click acolor to s elect it.3 Click OK on the color selec

Seite 585 - About Some Units Settings

Examples: Program GUI C omponentsNote Create your own icon with the icon editor described in “Icon Editor” onpage 15-63. See theind2rgb reference page

Seite 586

12 Code a Programmatic GUI1 Copy the f ollowing code into a file and save it in your current fo lderor on your path astoggle_plots.m. Execute the func

Seite 587 - Code a Programmatic G UI

Examples: Program GUI C omponents12-41

Seite 588 - 12 Code a Programmatic GUI

12 Code a Programmatic GUI2 Click the toggle tool to display the initial plot. The counter increments to 1.3 Continue clicking the toggle tool to togg

Seite 589 - Initialize a Programmatic GUI

13ManageApplication-Defined Data• “Ways to Manage Data in a Program m atic GUI” on page 13-2• “Share Data Among a GUI’s Callbacks” on page 13-11

Seite 590

Program the Simple GUIDE GUIIt then uses a switch statement to make the selected data set the currentdata. The last statement saves the changes to the

Seite 591 - MaketheFigureInvisible

13 Manage Application-Defined DataWays to Manage Data in a Programmatic GUIIn this section...“Data Management Mechanis m Summary” on page 13-2“Nested

Seite 592

Ways to Manage Data in a Programmatic GUIData-SharingMethodHow it WorksUse for...Pass function handlesor data through oneof the four followingmethods:

Seite 593 - Write Code for Callbacks

13 Manage Application-Defined Data• Nested Functions — Share variables defined at a higher level and callone another when called function is below abo

Seite 594

Ways to Manage Data in a Programmatic GUISee “Share Data with Nested Functions” on page 13-11 for a completeexample.UserData PropertyAll GUI component

Seite 595 - WriteCodeforCallbacks

13 Manage Application-Defined DataSee “Share Data with UserData” on page 13-15 for a complete example.Application DataApplication data is data that is

Seite 596

Ways to Manage Data in a Programmatic GUICreate Application DataUse the setappdata function to create application data. This examplegenerates a 35-by-

Seite 597

13 Manage Application-Defined DataGUI DataMost GUIs generate or use data that is specific to the application. Thesemechanisms provide a way for applic

Seite 598

Ways to Manage Data in a Programmatic GUIautomatically passed to each callback as hObject. S ee “Specify Callbacks inFunction Calls” on page 12-11 for

Seite 599 - Use Function Handle Callbacks

13 Manage Application-Defined DataNote To use hObject, you must specify a component’s callback propertiesas function handles. When you do, the compone

Seite 600

Share Data Among a GUI’s CallbacksShare Data Among a GUI’s CallbacksIn this section...“Share Data with Nested Functions” on page 13-11“Share Data with

Seite 601

2 How to Create a GUI with GUIDE1 Display the Surf push button callback in the MATLAB Editor. Right-clickthe Surf push button in the Layout Editor to

Seite 602

13 Manage Application-Defined DataThe GUI behavior is as follows:• When a user moves the slider, the edit text component displays the slider’scurrent

Seite 603

Share Data Among a GUI’s Callbacks'Callback',@slider_callback);eth = uicontrol(fh,'Style','edi t',...'String',

Seite 604

13 Manage Application-Defined Datanum2str(number_errors),' times.']);val = previous_val;endendendBecause the components are constructed at t

Seite 605

Share Data Among a GUI’s Callbacks• num2 str converts the value to a string.•set sets the String property of the edit text component to the updatedval

Seite 606

13 Manage Application-Defined DataUserData Property Example: Passing Data BetweenComponentsThefollowingcodeisthesameasinthepriorexample,“ShareDatawith

Seite 607

Share Data Among a GUI’s Callbacksset(eth,'String',num2str(slider.val) );sprintf('You changed the slider value by %6.2f percent.',

Seite 608

13 Manage Application-Defined DataSlider Values. In this example, both the slider callback, slider_callbac kand the edit text callback, edittext_callb

Seite 609 - List Box

Share Data Among a GUI’s Callbacksfunction slider _gui _appdatafh = figure('Position',[250 250 350 350],...'MenuBar','none&ap

Seite 610

13 Manage Application-Defined Dataslider_data.previous_val = slide r_data.val;slider_data.val = str2double(get(hObject,'String'));% Determin

Seite 611

Share Data Among a GUI’s CallbacksBoth callbacks use the getappdat a and s etappdata functions to retrieve andsave theslider_data structure as sl ider

Seite 612

Program the Simple GUIDE GUI3 Repeat steps 1 and 2 to add similar code to the Mesh and Contour pushbutton callbacks.• Add this code to the Mesh push b

Seite 613

13 Manage Application-Defined Data% ---------- ---- ----------------------- ---------------% Set the value of the edit text component String property%

Seite 614 - Resize property to on and

Share Data Among a GUI’s CallbacksSlider Values. In this example, both the slider callback, slide r_c allback,and the edit text callback,edittext_call

Seite 615

13 Manage Application-Defined Data13-24

Seite 616

14Manage Callback Execution

Seite 617 - Program Axes

14 Manage Ca llback Executio nCallback Sequencing and InterruptionIn this section...“Control C allback Execution and Interruption” on page 14-2“Contro

Seite 618

Callback Sequencing and InterruptionNote For information about what callbacks are and do, see “Write Code forCallbacks” on page 12-7 in this User’s Gu

Seite 619

14 Manage Ca llback Executio n3 KeyPressFcn (uicontrol and uitable callback)4 KeyReleaseFc n (in f ig ure window only)5 WindowKeyRel ease Fcn (in figu

Seite 620

Callback Sequencing and Interruption- WindowButton DownFcn- WindowButton MotionFcn- WindowButton UpFcn- WindowScroll WheelFcnFor callbacks that object

Seite 621

14 Manage Ca llback Executio nis taken into account only if the Inter ruptible property of the executingcallback’s object isoff, i.e., the executing c

Seite 622

Callback Sequencing and InterruptionThis code creates the two Wait butto n s and specifies th e callbacks thatservice them.h_interrupt = uicontrol(h_p

Seite 623 - Program Toolbar Tools

2 How to Create a GUI with GUIDEUsetheCompletedSimpleGUIDEGUIOpen and Run the GUIIn “Program the Simple GUIDE GUI” on page 2-28, you programmed thepop

Seite 624

14 Manage Ca llback Executio nThis code creates the two plot buttons and specifies the callbacks thatservice them.hsurf_queue = uicontrol(h_panel2,&ap

Seite 625 - Toggle Tool

Callback Sequencing and InterruptionNote This link executes MATLAB commands and is designed to work withinthe M ATLA B Help browser. If you are readin

Seite 626

14 Manage Ca llback Executio n% Enable the other push butto nset(h_noninterrupt,'Enable','on')endThe callback first disables the o

Seite 627

Callback Sequencing and Interruptionh_plot = surf(h_axes2,peaks_data) ;endViewtheCompleteGUICodeFile.If you are reading this in the MATLABHelp browser

Seite 628

14 Manage Ca llback Executio ndelete the timer before your GUI closes. To start a timer, call its st artmethod. The tim er executes its StartF cn, beg

Seite 629 - Application-Defined Data

15Examples of GUIs CreatedProgrammatically• “Techniques Explored by Programmatic GUI Examples” on page 15-2• “GUI with Axes, Menu, and Toolbar” on pag

Seite 630

15 Examples of GUIs Created ProgrammaticallyTechniques Explored by Programmatic GUI ExamplesThefivecompleteexamplesthatfollowillustratehowtocreateandp

Seite 631

Techniques Explored by Programmatic GUI ExamplesFor information about programming specific types of components, see“Examples: Program GUI Components”

Seite 632

15 Examples of GUIs Created ProgrammaticallyGUI with Axes, Menu, and ToolbarIn this section...“About the Axes, Menu, and Toolbar Example” on page 15-4

Seite 633

GUI with Axes, Menu, and ToolbarWhen you run the GUI, it initially displays a plot of fiv e random numbersgenerated by the MATLAB commandrand(5) comma

Seite 634

UsetheCompletedSimpleGUIDEGUIgive a GUI docking controls, but it must display a menu bar or a toolbarto enable them. For more information, see “How Me

Seite 635 - Create Application Data

15 Examples of GUIs Created ProgrammaticallyThe GUI toolbar has two buttons:• The Open buttonperforms the same function as the Open menu item. Itdispl

Seite 636

GUI with Axes, Menu, and Toolbar3 edit ico nRea d.m or Click he re to open the utility iconRead file in theEditor .If you just want to run the GUI and

Seite 637 - Create and Update GUI Data

15 Examples of GUIs Created Programmatically'plot(membrane)', @(a)plot(a,membrane);'surf(peaks)', @(a)surf(a,peaks)};Because the d

Seite 638

GUI with Axes, Menu, and Toolbar• Setting the HandleVisib ility property to callback ensures that thefigure can be accessed only from within a GUI cal

Seite 639 - UserData property to share

15 Examples of GUIs Created ProgrammaticallySee the Axes Properties reference page for information about axes propertiesand their default values.The P

Seite 640

GUI with Axes, Menu, and Toolbar• For a push button, the String property defines the label on the button.Here it is defined as the stringUpdate.• Sett

Seite 641

15 Examples of GUIs Created Programmaticallyit the child of the main figure. This statement creates a m enu bar in thefigure and puts the File menu on

Seite 642

GUI with Axes, Menu, and Toolbar• The uipusht ool function creates the two push buttons on the toolbar.• The uipushtoolTooltipString property assigns

Seite 643 - Share Data with UserData

15 Examples of GUIs Created ProgrammaticallyDefine the CallbacksThis topic defines the callbacks that service the components of the GUI.Because the ca

Seite 644 - Components

GUI with Axes, Menu, and ToolbarNote MATLAB software automatically passes hUpdateButtonCallbacktwo arguments, hObjec t and ev entd ata,becausetheUpdat

Seite 645

2 How to Create a GUI with GUIDE2-38

Seite 646

15 Examples of GUIs Created ProgrammaticallyThe hOpenM enu itemCallback function first calls the uigetfile function toopen the standard dialog box for

Seite 647

GUI with Axes, Menu, and ToolbarThe hPrintMenuitemCallback function calls the printdlg function. Thisfunction opens the standard system dial o g box f

Seite 648

15 Examples of GUIs Created Programmaticallydelete(hMainFigure);endThe hCloseMenuite mCal lback function calls the questdlg function to createand open

Seite 649 - Share Data with GUI Data

GUI that Displays and Graphs Tabular DataGUI that Displays and Graphs Tabular DataIn this section...“About the tableplot Example” on page 15-19“View a

Seite 650

15 Examples of GUIs Created ProgrammaticallyPlot columnsuitable withnamed columnsAxes withx- and y-labelsInitial promptThe table displays MATLAB sampl

Seite 651

GUI that Displays and Graphs Tabular DataThe tableplot main function creates a GUI figure with the following UIcomponents:• A uitable w ith three colu

Seite 652

15 Examples of GUIs Created ProgrammaticallyUIObjectHandle Callback Type Callback Signature RemarksCheckbox—Callback {@plot_callback,3}Plots a line gr

Seite 653

GUI that Displays and Graphs Tabular DataThe circle markers appear and disappear dynamically as the user selects cellsin the table. You do not need to

Seite 654 - Manage Ca llback Executio n

15 Examples of GUIs Created ProgrammaticallyPDF, go to the corresponding section in the MATL AB Help Browser to usethe links.If you intend to modify t

Seite 655 - Order of Callback Execution

GUI that Displays and Graphs Tabular DataThe main tableplot function sets up the uitable is immediately after loadingadatamatrixintotheworkspace. Thet

Seite 656 - - KeyReleaseFc n

3How to Create a SimpleGUI Programmatically• “About the Sim ple Programmatic GUI Example” on page 3-2• “Create the Simple Programmatic GUI Code File”

Seite 657

15 Examples of GUIs Created Programmatically% Create an axes on the right side; set x and y limits to the% table value extremes, and format labels for

Seite 658

GUI that Displays and Graphs Tabular Data% Callback to erase and replot markers, showing only those% corresponding to user-selected cells in table.% R

Seite 659

15 Examples of GUIs Created Programmatically3233If rows 5, 6, and 7 of columns 2 and 3 are selected,eventdata =Indices: [6x2 double]sel =525362637273A

Seite 660

GUI that Displays and Graphs Tabular Data• htab le — To fetch table data and column names for plotting the dataand deleting lines; thecolumn argument

Seite 661 - Click a Wait Button

15 Examples of GUIs Created ProgrammaticallyendendSubfunction Summary for tableplotThe tableplot ex ample conta in s the callbacks l isted in th e fol

Seite 662 - Click a Plot Button

GUI that Displays and Graphs Tabular Data• Parsecommand-lineargumentsspecifyingaworkspacevariabletoloadinto the table when the GUI opensIftheuserspeci

Seite 663

15 Examples of GUIs Created ProgrammaticallyThe data matrix might have colum ns with very different data ranges andunits of measure. Therefore, one ch

Seite 664

A GUI That Manages List DataAGUIThatManagesListDataIn this section...“About the List Master Example” on page 15-33“View and Run the List Master Code”

Seite 665 - Programmatically

15 Examples of GUIs Created ProgrammaticallyAn empty List Master GUI A List Master GUI with Controls and DataThe ComponentsA new List Master GUI figur

Seite 666

A GUI That Manages List Data- A list box, displaying an imported list- Three push buttons that respectively• M ove the selected item higher in the cur

Seite 667

Create GUIs with GUIDEWhat Is GUIDE?4GUIDE: Getting Started ... 4-2GUI Layout... 4-2GUI Pr

Seite 668

3 How to Create a Simple GUI ProgrammaticallyAbout the Simple Programmatic GUI ExampleSimple Programmatic GUI ComponentsThis section shows you how to

Seite 669

15 Examples of GUIs Created Programmatically• Automatically number list items and renumber them as needed (or not)• Give seve ral uicontrols the same

Seite 670

A GUI That Manages List DataIf you just want to run the GUI and inspect its code, follow these steps:1 ClickheretoaddtheexamplefilestotheMATLABpath(on

Seite 671

15 Examples of GUIs Created Programmatically3 TypeanameforthelistyouwanttocreateandclickOK.Ifyouwanttousethesampledataprovidedwiththisexample,youcanca

Seite 672 - The Main Figure

A GUI That Manages List DataFigure name Panel withlist nameSelectedlist itemEditablelist itemMove itemdown upToggle listnumberingDelete listitemEdit

Seite 673 - The Axes

15 Examples of GUIs Created ProgrammaticallyNote A List Master GUI has no facility to rename itself should someonereplace its contents. You can easily

Seite 674 - The Update Push Button

A GUI That Manages List Data1 Click on the list box item you want to copy or select the item’s text in theedit box.2 Type Ctrl+C to copy the item.3 Op

Seite 675 - TheFileMenuandItsMenuItems

15 Examples of GUIs Created ProgrammaticallyProgram List MasterThe List Master GUI code file contains 22 functions, organized into fivegroups.• “List

Seite 676 - The Toolbar and Its Tools

A GUI That Manages List DataMenuItemHow Used CallbackSaveas...Saves current List Master to adifferent F IG-filelmsaveasQuitExits List Master, with opt

Seite 677 - Initialize the GUI

15 Examples of GUIs Created ProgrammaticallyGUI. If the T ag has any other value, the program closes the figure anddisplays an error alert.The Quit me

Seite 678 - Define the Callbacks

A GUI That Manages List Databuttons that migrate items higher or lower in the list box. It disables the MoveUp button when the selected item is at the

Seite 679 - Open Menu Item Callback

About the Simple Programmatic GUI ExampleThe next topic, “Functions for the Simple Programmatic GUI” on page 3-3,summarizes the functions used to crea

Seite 680 - Print Menu Item Callback

15 Examples of GUIs Created ProgrammaticallyCalled from a blank GUI, the function requests a name, and then populatesthe figure with all controls. Cal

Seite 681

A GUI That Manages List DataList Master List CallbacksThe six callbacks not associated with m enu items are listed and describedbelow. Click any callb

Seite 682

15 Examples of GUIs Created Programmatically% Get the f igur e handle and from that, the listbo x handlefh = ancestor(hObject,'figure') ;lh

Seite 683 - About the tableplot Example

A GUI That Manages List DataUtility Function How Us e disguidirtyReturns logical state of the figure’s dirty flagmake_list_output_nameConverts the nam

Seite 684

15 Examples of GUIs Created ProgrammaticallyNote Use application data to communicate information betw een uicontrolsand other objects in GUIs you crea

Seite 685

Color PaletteColor PaletteIn this section...“About the Color Palette Example” on page 15-51“Techniques Used in the Color Palette Example” on page 15-5

Seite 686 - Callback {@plot_callback,3}

15 Examples of GUIs Created ProgrammaticallyThe colorPalette function populates a GUI figure or panel with a colorpalette. See “View and Run the C olo

Seite 687

Color Palette• A More Colors push button• A preview of the selected c olor, below the color cells, defined as a textcomponent• Text components to spec

Seite 688

15 Examples of GUIs Created ProgrammaticallyCall the colorPalette FunctionYou can call thecolorPalette function with a statement such asmGetColorFcn =

Seite 689

Color PaletteTechniques Usedin the Color Palette ExampleThis example illustrates the following techniques:• Retrieving output from the GUI when it ret

Seite 690 - The Cell Selection Callback

3 How to Create a Simple GUI ProgrammaticallyMATLAB Functions Used to Create the Simple Programmatic GUI(Continued)Function DescriptionmoveguiMove GUI

Seite 691

15 Examples of GUIs Created Programmatically3 Click here to display the GUI code file in the Editor (read-only).Note Do n o t save GUI files to the ex

Seite 692 - The Plot Check Box c allback

Color PaletteThe example also includes the helper functions listed in the following table.Function DescriptionlayoutComponentDynamically creates the E

Seite 693

15 Examples of GUIs Created Programmatically7 Callback definitions. These callbacks, which service the GUI components,are subfunctions of thecolorPale

Seite 694

Color PaletteThe colorPalette function then defines the valid custom properties in a3-by-3 cell array.mPropertyDefs = {... % The supported custom prop

Seite 695 - Col_1, C ol_2 ,

15 Examples of GUIs Created ProgrammaticallyPass Output to a Caller on ReturningIf a host GUI calls the colorPalette function with an output argument,

Seite 696 - YLim property is

Color PaletteJust before returning, colorPalette assigns mOutputArgs the functionhandle for itsgetSelectedColor helper function and then assignsmOutpu

Seite 697 - AGUIThatManagesListData

15 Examples of GUIs Created Programmaticallyy = ceil(pt(1,2));color = mGetColorFcn();% update color of the selecte d blockmIconCData(y, x,:) = color;l

Seite 698 - The Components

Icon EditorIcon EditorIn this section...“About the Icon Editor Example” on p age 15-63“View and Run the Icon Editor Code” on page 15-65“Subfunction Su

Seite 699 - - An “edit panel” containing

15 Examples of GUIs Created ProgrammaticallyIcon Editor GUI ComponentsThe GUIincludes the following components:• An edit text box that instructs the u

Seite 700

Icon Editor• A pane l, configured as a line , that separates the icon editor from the OKand Cancel buttons.• An OK push button that causes the GUI to

Seite 701 - UseListMaster

Create the Simple Programmatic GUI Code FileCreate the Simple Programmatic GUI Code FileStart by creating a file for the example GUI. Because the file

Seite 702

15 Examples of GUIs Created ProgrammaticallyPDF, go to the corresponding section in the MATL AB Help Browser to usethe links.If you intend to modify t

Seite 703 - Import Data into List Master

Icon EditorNote Do n o t save GUI files to the examples folder where you fo und them,or you will overwrite the original files. Save them to your curre

Seite 704 - Export Data from List Master

15 Examples of GUIs Created ProgrammaticallySubfunction SummaryThe icon editor e xample includes the callbacks listed in the following table.Function

Seite 705 - Save the GUI

Icon EditorFunction DescriptionlocalEditColorChanges the color of an icondata point to the currentlyselected color. Call the functionmGetColorFcn retu

Seite 706 - Program List Master

15 Examples of GUIs Created ProgrammaticallyCode File OrganizationThe iconEditor is programmed using nested functions. Its code is organized inthe fol

Seite 707 - A GUI That Manages List Data

Icon Editor• “Retrieve Output o n R eturn from a GUI” on page 15-73• “Protect a GUI from Inadvertent Access” on p age 15-74• “Run a GUI on Multiple Pl

Seite 708 - List Master Setup Functions

15 Examples of GUIs Created ProgrammaticallyWhen the user clicks the Cancel button, its callback,hOCancelButtonCallback, effectively deletes the icon

Seite 709 - List Master Menu Callbacks

Icon EditormIconWidth = 16; % Use input property ' iconwidth' to initializemIconHeight = 16; % Use input property 'ic onheight' to

Seite 710

15 Examples of GUIs Created ProgrammaticallymOutputArgs{} = mIco nCData;if nargout>0[varargout{1:nargout}] = mOutputAr gs{:};endThis code is the la

Seite 711 - List Master List Callbacks

Icon EditorRun a GUI on Multiple PlatformsThe prepareLayout utility function s ets various properties of all the GUIcomponents to enable the GUI to re

Seite 712 - List Master Utility Functions

3 How to Create a Simple GUI ProgrammaticallyThe next section, “Lay Out the Simple Programmatic GUI” on page 3-7, showsyou how to add components to yo

Seite 713

15 Examples of GUIs Created ProgrammaticallySelect Units. The prepareL ayou t function decides what units to use basedon the G UI’s resizability. It u

Seite 714

Icon EditorShare Data Between Two GUIsThe iconEditor embeds a GUI, the colorPalette, to enable the user to selectcolors for the icon cells. The colorP

Seite 715 - Color Palette

15 Examples of GUIs Created ProgrammaticallyThe iconEditor’s loca lEdi tColor helper function calls mGetColorFcn,the function returned bycolorPalette,

Seite 716

Icon Editorif strcmpi(get( topC ontainer, 'Resize') ,'on ')set(allObjects(isprop(allObjects,'Unit s')),...'Units&ap

Seite 717 - Use the Color Palette

15 Examples of GUIs Created Programmatically15-80

Seite 718

AExamplesUse th i s list to find examples in the documen ta t ion.

Seite 719 - View and Ru

A ExamplesSimple Examples (GUIDE)“About the SimpleGUIDEGUIExample”onpage2-9“Use a Modal Dialog Box to Confirm an Operation (GUIDE)” on page 10-98“Time

Seite 720

Simple Examples (Programmatic)Simple Examples (Programmatic)“About the S imple Programmatic GUI Example” on page 3-2A-3

Seite 721 - Code File Organization

A ExamplesApplication Examples (GUIDE)“A Working GUI with Many Components” on page 6-23“GUI with M ultiple Axes (GUIDE)” on page 10-2“GUI for Animatin

Seite 722 - GUI Programming Techniques

Programming GUI Components (GUIDE)Programming GUI Components (GUIDE)“Push Button” onpage 8-30“Toggle B utton” on page 8-31“Radio Button” on page 8-32“

Seite 723

LayOuttheSimpleProgrammaticGUILayOuttheSimpleProgrammaticGUIIn this section...“Create a Figure for a Programmatic GUI” on page 3-7“Add C omponents to

Seite 724 - Share Data Between Two GUIs

A ExamplesApplication-Defined Data (GUIDE)“Sharing Data with UserData” on page 9-11“Sharing Data with Application D ata” on page 9-14“Sharing Data wit

Seite 725

GUI Layout (Programmatic)GUI Layout (Programmatic)“File Template”on page 11-4“Check Box” on page 11-15“Edit Text” on page 11-17“ListBox”onpage 11-20“P

Seite 726

A ExamplesProgramming GUI Components (Programmatic)“Check Box” on page 12-21“Edit Text” on page 12-21“List B ox” on page 12-23“Pop-Up Menu”on page 12-

Seite 727 - Icon Editor

Application-Defined Data (Programmatic)Application-Defined Data (Programmatic)“Nested Functions Example: Passing Data Between Components” onpage 13-11

Seite 728 - Icon Editor GUI Components

A ExamplesApplication Examples (Programmatic)“GUI with Axes, Menu, and Toolbar” on page 15-4“GUI that Displays and Graphs Tabular Data” on page 15-19“

Seite 729

IndexIndexAActiveX controlsadding to GUI layout 6-77programming 8-49 12-34aligning componentsin GUIDE 6-89Alignment Objects ToolGUIDE 6-89application

Seite 730

Indexcontext menusassociating with an object 6-120creating in GUIDE 6-101creating with GUIDE 6-114menu items 6-116parent menu 6-114cross-platform comp

Seite 731

Indexlistmaster 15-33tableplot 15-19GUI exportconfirmation 5-2GUI FIG-filesopening 10-60GUI filesin GU IDE 7-2GUI initializationcontrolling for single

Seite 732 - Subfunction Summary

Indexinterrupting callbackexample of 10-22LLayout Editorshow component names 5-7Layout Editor windowshow file extension 5-7show file path 5-7list boxe

Seite 733

Indexcreating in GUIDE 6-114singleton GUIdefined 5-13GUIDE option 5-12size of GUIsetting w ith GUIDE 6-15sliders 6-21 11-12status barshow in GUIDE Lay

Seite 734 - Code File Organi

3 How to Create a Simple GUI Programmaticallyhcontour = uicontrol('Style','p ushbutton',...'String','Countour'

Seite 735

LayOuttheSimpleProgrammaticGUI4 Align all components except the axes along their centers with the followingstatement. Add it to the code file followin

Seite 736 - Pass Input Arguments to a GUI

3 How to Create a Simple GUI Programmatically7 Run your code by typing simple_gui2 at the command line. This is whatyour GUI now looks like. Note that

Seite 737

CodetheSimpleProgrammaticGUICode the Simple Programmatic GUIIn this section...“Program the Pop-Up Menu” on page 3-11“Program the Push Buttons” on page

Seite 738

Select a GUI Template ... 6-6Access the Templates... 6-6Template Descriptions...

Seite 739

3 How to Create a Simple GUI ProgrammaticallyendThe next topic, “Program the Push Buttons” on page 3-12, shows you how towrite callbacks for the three

Seite 740 - Make a GUI Modal

CodetheSimpleProgrammaticGUIthat particular event. But how does the software know which callback toexecute? You must use each component’sCallback prop

Seite 741

3 How to Create a Simple GUI Programmaticallyresize when the GUI is resized. Normalized units map the lower-left cornerofthefigurewindowto(0,0) and th

Seite 742

CodetheSimpleProgrammaticGUIfunction simple _gui 2% SIMPLE_GUI 2 Select a data set from the pop-u p menu, then% click one of the plot-typ e push butto

Seite 743

3 How to Create a Simple GUI Programmaticallyset(f,'Name','Simple GUI')% Move the GUI to the center of the sc reen .movegui(f,&apo

Seite 744

CodetheSimpleProgrammaticGUI% Create and then hide the GUI as it is being constructed.f = figure('Visible','off','Pos ition&a

Seite 745

3 How to Create a Simple GUI Programmaticallyset(f,'Name','Simple GUI')% Move the GUI to the center of the sc reen .movegui(f,&apo

Seite 746 - Simple Examples (GUIDE)

CodetheSimpleProgrammaticGUIfunction con tour button_Callback(source, eventdata)% Display contour plot of the currently se lected data.contour(current

Seite 747 - “About the S impl

3 How to Create a Simple GUI ProgrammaticallyUse the Completed Simple Programmatic GUIOpen and Run the GUI1 Run the GUI by typing the name of the code

Seite 748 - Application Examples (GUIDE)

UsetheCompletedSimpleProgrammaticGUI3 Try other combinations before closing the GUI.3-21

Seite 749

Standard Background C olor ... 6-138Cross-Platform Compatible Units... 6-139Save and Run a GUIDE GUI7Name a GUI

Seite 750 - A Examples

3 How to Create a Simple GUI Programmatically3-22

Seite 751 - GUI Layout (Programmatic)

Create GUIs with GUIDEChapter 4, What Is GUIDE?(p. 4-1)Introduces GUIDEChapter 5, G UIDE Preferencesand Options (p. 5-1)Describes briefly the availabl

Seite 753

4What Is GUIDE?• “GUIDE : Getting Started” on page 4-2• “GUIDE Tools Summary” on page 4-3

Seite 754

4 What Is GUIDE?GUIDE: Getting StartedIn this section...“GUI Layout” on page 4-2“GUI Programming” on page 4-2GUI LayoutGUIDE, the MATLAB graphical use

Seite 755 - UserData property 9-5 13-5

GUIDE Tools SummaryGUIDE Tools Summar yThe GUIDE tools are available from the Layout Editor shown in the figurebelow. The tools are called out in the

Seite 756

4 What Is GUIDE?Use ThisTool... To...LayoutEditorSelect components from the component palette, at the leftside of the Layout Editor, and arrange them

Seite 757

GUIDE Tools SummaryUse ThisTool... To...EditorDisplay, in your default editor, the code file associated withthe GUI. See “Files Generated by GUIDE” o

Seite 758 - NextPlot

4 What Is GUIDE?4-6

Seite 759 - UserData property

5GUIDE Preferences andOptions• “GUIDE Preferences” on page 5-2• “GUI Options” on page 5-9

Kommentare zu diesen Handbüchern

Keine Kommentare