logo资料库

Matlab界面GUI编程官方教程2017版.pdf

第1页 / 共500页
第2页 / 共500页
第3页 / 共500页
第4页 / 共500页
第5页 / 共500页
第6页 / 共500页
第7页 / 共500页
第8页 / 共500页
资料共500页,剩余部分请下载后查看
MATLAB® App Building R2017a
How to Contact MathWorks Latest news: Sales and services: User community: Technical support: Phone: www.mathworks.com www.mathworks.com/sales_and_services www.mathworks.com/matlabcentral www.mathworks.com/support/contact_us 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 June 2001 Online Only Online Only July 2002 Online Only June 2004 Online Only October 2004 March 2005 Online Only September 2005 Online Only Online Only March 2006 May 2006 Online Only September 2006 Online Only March 2007 Online Only September 2007 Online Only Online Only March 2008 Online Only October 2008 March 2009 Online Only September 2009 Online Only March 2010 Online Only September 2010 Online Only April 2011 Online Only September 2011 Online Only March 2012 Online Only September 2012 Online Only March 2013 Online Only September 2013 Online Only Online Only March 2014 October 2014 Online Only March 2015 Online Only September 2015 Online Only March 2016 Online Only September 2016 Online Only March 2017 Online Only New for MATLAB 6.0 (Release 12) Revised for MATLAB 6.1 (Release 12.1) Revised for MATLAB 6.6 (Release 13) Revised for MATLAB 7.0 (Release 14) Revised for MATLAB 7.0.1 (Release 14SP1) Revised for MATLAB 7.0.4 (Release 14SP2) Revised for MATLAB 7.1 (Release 14SP3) Revised for MATLAB 7.2 (Release 2006a) Revised for MATLAB 7.2 Revised for MATLAB 7.3 (Release 2006b) Revised for MATLAB 7.4 (Release 2007a) Revised for MATLAB 7.5 (Release 2007b) Revised for MATLAB 7.6 (Release 2008a) Revised for MATLAB 7.7 (Release 2008b) Revised for MATLAB 7.8 (Release 2009a) Revised for MATLAB 7.9 (Release 2009b) Revised for MATLAB 7.10 (Release 2010a) Revised for MATLAB 7.11 (Release 2010b) Revised for MATLAB 7.12 (Release 2011a) Revised for MATLAB 7.13 (Release 2011b) Revised for MATLAB 7.14 (Release 2012a) Revised for MATLAB 8.0 (Release 2012b) Revised for MATLAB 8.1 (Release 2013a) Revised for MATLAB 8.2 (Release 2013b) Revised for MATLAB 8.3 (Release 2014a) Revised for MATLAB 8.4 (Release 2014b) Revised for MATLAB 8.5 (Release 2015a) Revised for MATLAB 8.6 (Release 2015b) Revised for MATLAB 9.0 (Release 2016a) Revised for MATLAB 9.1 (Release 2016b) Revised for MATLAB 9.2 (Release 2017a)
Contents Introduction to Creating UIs About Apps in MATLAB Software Ways to Build Apps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Use GUIDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Use MATLAB Functions to Create Apps Programmatically . . . . . . . . . . . . . . . . . . . . . . . . . . . Use App Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 1-2 1-3 1-5 How to Create a App with GUIDE 1 2 Create a Simple App Using GUIDE . . . . . . . . . . . . . . . . . Open a New UI in the GUIDE Layout Editor . . . . . . . . Set the Window Size in GUIDE . . . . . . . . . . . . . . . . . . Layout the UI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Code the Behavior of the App . . . . . . . . . . . . . . . . . . . Run the App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Files Generated by GUIDE . . . . . . . . . . . . . . . . . . . . . . . Code Files and FIG-Files . . . . . . . . . . . . . . . . . . . . . . . Code File Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding Callback Templates to an Existing Code File . . About GUIDE-Generated Callbacks . . . . . . . . . . . . . . 2-2 2-3 2-5 2-6 2-16 2-22 2-24 2-24 2-24 2-25 2-26 v
3 A Simple Programmatic App Create a Simple App Programmatically . . . . . . . . . . . . . Create a Code File . . . . . . . . . . . . . . . . . . . . . . . . . . . . Create the Figure Window . . . . . . . . . . . . . . . . . . . . . . Add Components to the UI . . . . . . . . . . . . . . . . . . . . . . Code the App’s Behavior . . . . . . . . . . . . . . . . . . . . . . . . Verify Code and Run the App . . . . . . . . . . . . . . . . . . . 3-2 3-3 3-3 3-4 3-7 3-11 Create UIs with GUIDE 4 5 What Is GUIDE? GUIDE: Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . UI Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . UI Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2 4-2 4-2 GUIDE Preferences and Options GUIDE Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Set Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Confirmation Preferences . . . . . . . . . . . . . . . . . . . . . . . Backward Compatibility Preference . . . . . . . . . . . . . . . All Other Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . GUIDE Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The GUI Options Dialog Box . . . . . . . . . . . . . . . . . . . . . Resize Behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Command-Line Accessibility . . . . . . . . . . . . . . . . . . . . . Generate FIG-File and MATLAB File . . . . . . . . . . . . . Generate FIG-File Only . . . . . . . . . . . . . . . . . . . . . . . 5-2 5-2 5-2 5-4 5-4 5-8 5-8 5-9 5-9 5-10 5-12 vi Contents
6 Lay Out a UI Using GUIDE GUIDE Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Access the Templates . . . . . . . . . . . . . . . . . . . . . . . . . . Template Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . Set the UI Window Size in GUIDE . . . . . . . . . . . . . . . . . Prevent Existing Objects from Resizing with the Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Set the Window Position or Size to an Exact Value . . . Maximize the Layout Area . . . . . . . . . . . . . . . . . . . . . Add Components to the GUIDE Layout Area . . . . . . . . Place Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . User Interface Controls . . . . . . . . . . . . . . . . . . . . . . . . Panels and Button Groups . . . . . . . . . . . . . . . . . . . . . Axes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ActiveX Component . . . . . . . . . . . . . . . . . . . . . . . . . . . Resize GUIDE UI Components . . . . . . . . . . . . . . . . . . Align GUIDE UI Components . . . . . . . . . . . . . . . . . . . . . Align Objects Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . Property Inspector . . . . . . . . . . . . . . . . . . . . . . . . . . . . Grid and Rulers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Guide Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Customize Tabbing Behavior in a GUIDE UI . . . . . . . . Create Menus for GUIDE Apps . . . . . . . . . . . . . . . . . . . Menus for the Menu Bar . . . . . . . . . . . . . . . . . . . . . . . Context Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Create Toolbars for GUIDE UIs . . . . . . . . . . . . . . . . . . . Toolbar and Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . Editing Tool Icons . . . . . . . . . . . . . . . . . . . . . . . . . . . Design Cross-Platform UIs in GUIDE . . . . . . . . . . . . . Default System Font . . . . . . . . . . . . . . . . . . . . . . . . . Standard Background Color . . . . . . . . . . . . . . . . . . . Cross-Platform Compatible Units . . . . . . . . . . . . . . . 6-2 6-2 6-3 6-11 6-11 6-12 6-12 6-13 6-13 6-19 6-40 6-45 6-49 6-60 6-62 6-65 6-65 6-68 6-71 6-72 6-74 6-77 6-77 6-87 6-94 6-94 6-102 6-105 6-105 6-106 6-106 vii
7 8 Programming a GUIDE App Write Callbacks in GUIDE . . . . . . . . . . . . . . . . . . . . . . . . Callbacks for Different User Actions . . . . . . . . . . . . . . . GUIDE-Generated Callback Functions and Property Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . GUIDE Callback Syntax . . . . . . . . . . . . . . . . . . . . . . . . Renaming and Removing GUIDE-Generated Callbacks . Initialize UI Components in GUIDE Apps . . . . . . . . . . . Opening Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Output Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Callbacks for Specific Components . . . . . . . . . . . . . . . . How to Use the Example Code . . . . . . . . . . . . . . . . . . Push Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Toggle Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Radio Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Check Box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Edit Text Field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Slider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . List Box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Pop-Up Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Button Group . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Menu Item . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Axes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Examples of GUIDE Apps . . . . . . . . . . . . . . . . . . . . . . . . 7-2 7-2 7-4 7-5 7-5 7-7 7-7 7-9 7-11 7-11 7-12 7-12 7-13 7-14 7-14 7-15 7-16 7-18 7-20 7-21 7-22 7-25 7-26 7-29 Examples of GUIDE UIs Modal Dialog Box in GUIDE . . . . . . . . . . . . . . . . . . . . . . Create the Dialog Box . . . . . . . . . . . . . . . . . . . . . . . . . . Create the Program That Opens the Dialog Box . . . . . . Run the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2 8-2 8-3 8-5 viii Contents
分享到:
收藏