ebook img

MATLAB Creating Graphical User Interfaces PDF

508 Pages·2016·6.32 MB·English
by  
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview MATLAB Creating Graphical User Interfaces

® MATLAB App Building R2017a How to Contact MathWorks Latest news: www.mathworks.com Sales and services: www.mathworks.com/sales_and_services User community: www.mathworks.com/matlabcentral Technical support: www.mathworks.com/support/contact_us Phone: 508-647-7000 The MathWorks, Inc. 3 Apple Hill Drive Natick, MA 01760-2098 MATLAB® App Building © COPYRIGHT 2000–2017 by The MathWorks, Inc. The software described in this document is furnished under a license agreement. The software may be used or copied only under the terms of the license agreement. No part of this manual may be photocopied or reproduced in any form without prior written consent from The MathWorks, Inc. FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation by, for, or through the federal government of the United States. By accepting delivery of the Program or Documentation, the government hereby agrees that this software or documentation qualifies as commercial computer software or commercial computer software documentation as such terms are used or defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms and conditions of this Agreement and only those rights specified in this Agreement, shall pertain to and govern the use, modification, reproduction, release, performance, display, and disclosure of the Program and Documentation by the federal government (or other entity acquiring for or through the federal government) and shall supersede any conflicting contractual terms or conditions. If this License fails to meet the government's needs or is inconsistent in any respect with federal procurement law, the government agrees to return the Program and Documentation, unused, to The MathWorks, Inc. Trademarks MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand names may be trademarks or registered trademarks of their respective holders. Patents MathWorks products are protected by one or more U.S. patents. Please see www.mathworks.com/patents for more information. Revision History November 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 Only Revised for MATLAB 6.6 (Release 13) June 2004 Online Only Revised for MATLAB 7.0 (Release 14) October 2004 Online Only Revised for MATLAB 7.0.1 (Release 14SP1) March 2005 Online Only Revised for MATLAB 7.0.4 (Release 14SP2) September 2005 Online Only Revised for MATLAB 7.1 (Release 14SP3) March 2006 Online Only Revised for MATLAB 7.2 (Release 2006a) May 2006 Online Only Revised for MATLAB 7.2 September 2006 Online Only Revised for MATLAB 7.3 (Release 2006b) March 2007 Online Only Revised for MATLAB 7.4 (Release 2007a) September 2007 Online Only Revised for MATLAB 7.5 (Release 2007b) March 2008 Online Only Revised for MATLAB 7.6 (Release 2008a) October 2008 Online Only Revised for MATLAB 7.7 (Release 2008b) March 2009 Online Only Revised for MATLAB 7.8 (Release 2009a) September 2009 Online Only Revised for MATLAB 7.9 (Release 2009b) March 2010 Online Only Revised for MATLAB 7.10 (Release 2010a) September 2010 Online Only Revised for MATLAB 7.11 (Release 2010b) April 2011 Online Only Revised for MATLAB 7.12 (Release 2011a) September 2011 Online Only Revised for MATLAB 7.13 (Release 2011b) March 2012 Online Only Revised for MATLAB 7.14 (Release 2012a) September 2012 Online Only Revised for MATLAB 8.0 (Release 2012b) March 2013 Online Only Revised for MATLAB 8.1 (Release 2013a) September 2013 Online Only Revised for MATLAB 8.2 (Release 2013b) March 2014 Online Only Revised for MATLAB 8.3 (Release 2014a) October 2014 Online Only Revised for MATLAB 8.4 (Release 2014b) March 2015 Online Only Revised for MATLAB 8.5 (Release 2015a) September 2015 Online Only Revised for MATLAB 8.6 (Release 2015b) March 2016 Online Only Revised for MATLAB 9.0 (Release 2016a) September 2016 Online Only Revised for MATLAB 9.1 (Release 2016b) March 2017 Online Only Revised for MATLAB 9.2 (Release 2017a) Contents Introduction to Creating UIs About Apps in MATLAB Software 1 Ways to Build Apps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 Use GUIDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 Use MATLAB Functions to Create Apps Programmatically . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3 Use App Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5 How to Create a App with GUIDE 2 Create a Simple App Using GUIDE . . . . . . . . . . . . . . . . . 2-2 Open a New UI in the GUIDE Layout Editor . . . . . . . . 2-3 Set the Window Size in GUIDE . . . . . . . . . . . . . . . . . . 2-5 Layout the UI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6 Code the Behavior of the App . . . . . . . . . . . . . . . . . . . 2-16 Run the App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-22 Files Generated by GUIDE . . . . . . . . . . . . . . . . . . . . . . . 2-24 Code Files and FIG-Files . . . . . . . . . . . . . . . . . . . . . . . 2-24 Code File Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-24 Adding Callback Templates to an Existing Code File . . 2-25 About GUIDE-Generated Callbacks . . . . . . . . . . . . . . 2-26 v A Simple Programmatic App 3 Create a Simple App Programmatically . . . . . . . . . . . . . 3-2 Create a Code File . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3 Create the Figure Window . . . . . . . . . . . . . . . . . . . . . . 3-3 Add Components to the UI . . . . . . . . . . . . . . . . . . . . . . 3-4 Code the App’s Behavior . . . . . . . . . . . . . . . . . . . . . . . . 3-7 Verify Code and Run the App . . . . . . . . . . . . . . . . . . . 3-11 Create UIs with GUIDE What Is GUIDE? 4 GUIDE: Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2 UI Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2 UI Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2 GUIDE Preferences and Options 5 GUIDE Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2 Set Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2 Confirmation Preferences . . . . . . . . . . . . . . . . . . . . . . . 5-2 Backward Compatibility Preference . . . . . . . . . . . . . . . 5-4 All Other Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4 GUIDE Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-8 The GUI Options Dialog Box . . . . . . . . . . . . . . . . . . . . . 5-8 Resize Behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-9 Command-Line Accessibility . . . . . . . . . . . . . . . . . . . . . 5-9 Generate FIG-File and MATLAB File . . . . . . . . . . . . . 5-10 Generate FIG-File Only . . . . . . . . . . . . . . . . . . . . . . . 5-12 vi Contents Lay Out a UI Using GUIDE 6 GUIDE Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2 Access the Templates . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2 Template Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3 Set the UI Window Size in GUIDE . . . . . . . . . . . . . . . . . 6-11 Prevent Existing Objects from Resizing with the Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-11 Set the Window Position or Size to an Exact Value . . . 6-12 Maximize the Layout Area . . . . . . . . . . . . . . . . . . . . . 6-12 Add Components to the GUIDE Layout Area . . . . . . . . 6-13 Place Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-13 User Interface Controls . . . . . . . . . . . . . . . . . . . . . . . . 6-19 Panels and Button Groups . . . . . . . . . . . . . . . . . . . . . 6-40 Axes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-45 Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-49 ActiveX Component . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-60 Resize GUIDE UI Components . . . . . . . . . . . . . . . . . . 6-62 Align GUIDE UI Components . . . . . . . . . . . . . . . . . . . . . 6-65 Align Objects Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-65 Property Inspector . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-68 Grid and Rulers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-71 Guide Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-72 Customize Tabbing Behavior in a GUIDE UI . . . . . . . . 6-74 Create Menus for GUIDE Apps . . . . . . . . . . . . . . . . . . . 6-77 Menus for the Menu Bar . . . . . . . . . . . . . . . . . . . . . . . 6-77 Context Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-87 Create Toolbars for GUIDE UIs . . . . . . . . . . . . . . . . . . . 6-94 Toolbar and Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-94 Editing Tool Icons . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-102 Design Cross-Platform UIs in GUIDE . . . . . . . . . . . . . 6-105 Default System Font . . . . . . . . . . . . . . . . . . . . . . . . . 6-105 Standard Background Color . . . . . . . . . . . . . . . . . . . 6-106 Cross-Platform Compatible Units . . . . . . . . . . . . . . . 6-106 vii Programming a GUIDE App 7 Write Callbacks in GUIDE . . . . . . . . . . . . . . . . . . . . . . . . 7-2 Callbacks for Different User Actions . . . . . . . . . . . . . . . 7-2 GUIDE-Generated Callback Functions and Property Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-4 GUIDE Callback Syntax . . . . . . . . . . . . . . . . . . . . . . . . 7-5 Renaming and Removing GUIDE-Generated Callbacks . 7-5 Initialize UI Components in GUIDE Apps . . . . . . . . . . . 7-7 Opening Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-7 Output Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-9 Callbacks for Specific Components . . . . . . . . . . . . . . . . 7-11 How to Use the Example Code . . . . . . . . . . . . . . . . . . 7-11 Push Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-12 Toggle Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-12 Radio Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-13 Check Box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-14 Edit Text Field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-14 Slider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-15 List Box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-16 Pop-Up Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-18 Panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-20 Button Group . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-21 Menu Item . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-22 Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-25 Axes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-26 Examples of GUIDE Apps . . . . . . . . . . . . . . . . . . . . . . . . 7-29 Examples of GUIDE UIs 8 Modal Dialog Box in GUIDE . . . . . . . . . . . . . . . . . . . . . . 8-2 Create the Dialog Box . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2 Create the Program That Opens the Dialog Box . . . . . . 8-3 Run the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-5 viii Contents GUIDE App With Parameters for Displaying Plots . . . . 8-7 Open and Run the Example . . . . . . . . . . . . . . . . . . . . . 8-7 Examine the Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-8 GUIDE App Containing Tables and Plots . . . . . . . . . . . 8-12 Open and Run the Example . . . . . . . . . . . . . . . . . . . . 8-12 Examine the Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-13 Interactive List Box App in GUIDE . . . . . . . . . . . . . . . . 8-16 Open and Run The Example . . . . . . . . . . . . . . . . . . . . 8-16 Examine the Layout and Callback Code . . . . . . . . . . . 8-18 Plot Workspace Variables in a GUIDE App . . . . . . . . . 8-21 Open and Run the Example . . . . . . . . . . . . . . . . . . . . 8-21 Examine the Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-22 Automatically Refresh Plot in a GUIDE App . . . . . . . . 8-24 Open and Run the Example . . . . . . . . . . . . . . . . . . . . 8-24 Examine the Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-25 Create UIs Programmatically Lay Out a Programmatic UI 9 Structure of Programmatic App Code Files . . . . . . . . . . 9-2 File Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-2 File Template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-2 Run the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-3 Add Components to a Programmatic App . . . . . . . . . . . 9-4 User Interface Controls . . . . . . . . . . . . . . . . . . . . . . . . . 9-4 Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-16 Panels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-17 Button Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-19 Axes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-21 ActiveX Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-23 How to Set Font Characteristics . . . . . . . . . . . . . . . . . 9-23 ix Lay Out a UI Programmatically . . . . . . . . . . . . . . . . . . 9-26 Component Placement and Sizing . . . . . . . . . . . . . . . . 9-26 Managing the Layout in Resizable UIs . . . . . . . . . . . . 9-31 Manage the Stacking Order of Grouped Components . . 9-34 Customize Tabbing Behavior in a Programmatic App 9-35 How Tabbing Works . . . . . . . . . . . . . . . . . . . . . . . . . . 9-35 Default Tab Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-35 Change the Tab Order in the uipanel . . . . . . . . . . . . . 9-37 Create Menus for Programmatic Apps . . . . . . . . . . . . . 9-39 Add Menu Bar Menus . . . . . . . . . . . . . . . . . . . . . . . . . 9-39 Add Context Menus to a Programmatic App . . . . . . . . 9-46 Create Toolbars for Programmatic Apps . . . . . . . . . . . 9-52 Use the uitoolbar Function . . . . . . . . . . . . . . . . . . . . . 9-52 Commonly Used Properties . . . . . . . . . . . . . . . . . . . . . 9-52 Toolbars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-53 Display and Modify the Standard Toolbar . . . . . . . . . . 9-56 DPI-Aware Behavior in MATLAB . . . . . . . . . . . . . . . . . 9-59 Visual Appearance . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-59 Using Object Properties . . . . . . . . . . . . . . . . . . . . . . . 9-61 Using print, getframe, and publish Functions . . . . . . . 9-62 Code a Programmatic App 10 Initialize a Programmatic App . . . . . . . . . . . . . . . . . . . 10-2 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2 Write Callbacks for Apps Created Programmatically . 10-5 Callbacks for Different User Actions . . . . . . . . . . . . . . 10-5 How to Specify Callback Property Values . . . . . . . . . . 10-7 x Contents

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.