ebook img

MATLAB Object-Oriented Programming PDF

818 Pages·2016·4.2 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 Object-Oriented Programming

MATLAB® Object-Oriented Programming R2021b 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. 1 Apple Hill Drive Natick, MA 01760-2098 Object-Oriented Programming © COPYRIGHT 1984–2021 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 March 2008 Online only New 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 Version 7.11 (Release 2010b) April 2011 Online only Revised for Version 7.12 (Release 2011a) September 2011 Online only Revised for Version 7.13 (Release 2011b) March 2012 Online only Revised for Version 7.14 (Release 2012a) September 2012 Online only Revised for Version 8.0 (Release 2012b) March 2013 Online only Revised for Version 8.1 (Release 2013a) September 2013 Online only Revised for Version 8.2 (Release 2013b) March 2014 Online only Revised for Version 8.3 (Release 2014a) October 2014 Online only Revised for Version 8.4 (Release 2014b) March 2015 Online only Revised for Version 8.5 (Release 2015a) September 2015 Online only Revised for Version 8.6 (Release 2015b) March 2016 Online only Revised for Version 9.0 (Release 2016a) September 2016 Online only Revised for Version 9.1 (Release 2016b) March 2017 Online only Revised for Version 9.2 (Release 2017a) September 2017 Online only Revised for Version 9.3 (Release 2017b) March 2018 Online only Revised for MATLAB 9.4 (Release 2018a) September 2018 Online only Revised for Version 9.5 (Release 2018b) March 2019 Online only Revised for MATLAB 9.6 (Release 2019a) September 2019 Online only Revised for MATLAB 9.7 (Release 2019b) March 2020 Online only Revised for MATLAB 9.8 (Release 2020a) September 2020 Online only Revised for MATLAB 9.9 (Release 2020b) March 2021 Online only Revised for MATLAB 9.10 (Release 2021a) September 2021 Online only Revised for MATLAB 9.11 (Release 2021b) Contents Using Object-Oriented Design in MATLAB 1 Why Use Object-Oriented Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 Approaches to Writing MATLAB Programs . . . . . . . . . . . . . . . . . . . . . . . . 1-2 When Should You Create Object-Oriented Programs . . . . . . . . . . . . . . . . . 1-2 Handle Object Behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7 What Is a Handle? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7 Copies of Handles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7 Handle Objects Modified in Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8 Determine If an Object Is a Handle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9 Deleted Handle Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9 Basic Example 2 Creating a Simple Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 Design Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 Create Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3 Access Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3 Call Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3 Add Constructor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4 Vectorize Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4 Overload Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5 BasicClass Code Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6 MATLAB Classes Overview 3 Role of Classes in MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2 Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2 Some Basic Relationships . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3 Developing Classes That Work Together . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6 Formulating a Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6 Specifying Class Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7 BankAccount Class Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7 Formulating the AccountManager Class . . . . . . . . . . . . . . . . . . . . . . . . . 3-10 Implementing the AccountManager Class . . . . . . . . . . . . . . . . . . . . . . . . 3-11 AccountManager Class Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-11 v Using BankAccount Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-12 Representing Structured Data with Classes . . . . . . . . . . . . . . . . . . . . . . . 3-14 Objects as Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-14 Structure of the Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-14 The TensileData Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 Create an Instance and Assign Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 Restrict Properties to Specific Values . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16 Simplifying the Interface with a Constructor . . . . . . . . . . . . . . . . . . . . . . 3-16 Calculate Data on Demand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-17 Displaying TensileData Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-18 Method to Plot Stress vs. Strain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-18 TensileData Class Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-19 Implementing Linked Lists with Classes . . . . . . . . . . . . . . . . . . . . . . . . . . 3-23 Class Definition Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-23 dlnode Class Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-23 Create Doubly Linked List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-24 Why a Handle Class for Linked Lists? . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-25 dlnode Class Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-25 Specialize the dlnode Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-34 Static Data 4 Static Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2 What Is Static Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2 Static Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2 Static Data Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3 Constant Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4 Class Definition—Syntax Reference 5 Class Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2 Class Building Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2 Class Definition Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2 Properties Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3 Methods Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3 Events Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4 Attribute Specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4 Enumeration Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5 Related Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6 Define Class Methods and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-7 The Methods Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-7 Method Calling Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-7 Private Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-8 More Detailed Information on Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-8 vi Contents Class-Related Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-8 How to Overload Functions and Operators . . . . . . . . . . . . . . . . . . . . . . . . 5-9 Rules for Defining Methods in Separate Files . . . . . . . . . . . . . . . . . . . . . . 5-9 Attribute Specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-11 Attribute Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-11 Attribute Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-11 Attribute Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-11 Simpler Syntax for true/false Attributes . . . . . . . . . . . . . . . . . . . . . . . . . 5-12 Call Superclass Methods on Subclass Objects . . . . . . . . . . . . . . . . . . . . . 5-13 Superclass Relation to Subclass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-13 How to Call Superclass Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-13 How to Call Superclass Constructor . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-13 Using a Class to Display Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-15 Class Calculates Area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-15 Description of Class Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-17 MATLAB Code Analyzer Warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-20 Syntax Warnings and Property Names . . . . . . . . . . . . . . . . . . . . . . . . . . 5-20 Variable/Property Name Conflict Warnings . . . . . . . . . . . . . . . . . . . . . . . 5-20 Exception to Variable/Property Name Rule . . . . . . . . . . . . . . . . . . . . . . . 5-21 Objects In Conditional Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-22 Enable Use of Objects in Conditional Statements . . . . . . . . . . . . . . . . . . 5-22 How MATLAB Evaluates Switch Statements . . . . . . . . . . . . . . . . . . . . . . 5-22 How to Define the eq Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-23 Enumerations in Switch Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-25 Use of Editor and Debugger with Classes . . . . . . . . . . . . . . . . . . . . . . . . . 5-27 Write Class Code in the Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-27 How to Refer to Class Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-27 How to Debug Class Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-27 Automatic Updates for Modified Classes . . . . . . . . . . . . . . . . . . . . . . . . . . 5-29 When MATLAB Loads Class Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . 5-29 Consequences of Automatic Update . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-29 What Happens When Class Definitions Change . . . . . . . . . . . . . . . . . . . . 5-30 Ensure Defining Folder Remains in Scope . . . . . . . . . . . . . . . . . . . . . . . . 5-30 Actions That Do Not Trigger Updates . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-31 Multiple Updates to Class Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-31 Object Validity with Deleted Class File . . . . . . . . . . . . . . . . . . . . . . . . . . 5-31 When Updates Are Not Possible . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-31 Potential Consequences of Class Updates . . . . . . . . . . . . . . . . . . . . . . . . 5-31 Interactions with the Debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-32 Updates to Class Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-32 Updates to Property Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-32 Updates to Method Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-33 Updates to Event Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-34 Comparison of MATLAB and Other OO Languages . . . . . . . . . . . . . . . . . . 5-36 Some Differences from C++ and Java Code . . . . . . . . . . . . . . . . . . . . . . 5-36 Object Modification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-37 Static Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-40 vii Common Object-Oriented Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-40 Defining and Organizing Classes 6 User-Defined Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2 What Is a Class Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2 Attributes for Class Members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2 Kinds of Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2 Constructing Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3 Class Hierarchies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3 classdef Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3 Class Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3 Class Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-5 Specifying Class Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-5 Specifying Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-7 Class-Specific Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-7 Evaluation of Expressions in Class Definitions . . . . . . . . . . . . . . . . . . . . . . 6-8 Why Use Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-8 Where to Use Expressions in Class Definitions . . . . . . . . . . . . . . . . . . . . . 6-8 How MATLAB Evaluates Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-10 When MATLAB Evaluates Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . 6-10 Expression Evaluation in Handle and Value Classes . . . . . . . . . . . . . . . . 6-10 Folders Containing Class Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-13 Class Definitions on the Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-13 Class and Path Folders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-13 Using Path Folders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-13 Using Class Folders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-14 Functions in Private Folders Within Class Folders . . . . . . . . . . . . . . . . . . 6-14 Class Precedence and MATLAB Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-15 Changing Path to Update Class Definition . . . . . . . . . . . . . . . . . . . . . . . . 6-16 Class Precedence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-18 Use of Class Precedence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-18 Why Mark Classes as Inferior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-18 InferiorClasses Attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-18 Packages Create Namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-20 Package Folders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-20 Internal Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-20 Referencing Package Members Within Packages . . . . . . . . . . . . . . . . . . . 6-21 Referencing Package Members from Outside the Package . . . . . . . . . . . 6-21 Packages and the MATLAB Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-22 Import Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-24 Syntax for Importing Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-24 Import Static Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-24 Import Package Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-24 Package Function and Class Method Name Conflict . . . . . . . . . . . . . . . . 6-25 viii Contents Clearing Import List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-25 Creating and Managing Class Aliases . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-26 Rename a Class Multiple Times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-26 Rename Multiple Classes in a Single Function . . . . . . . . . . . . . . . . . . . . 6-27 Value or Handle Class — Which to Use 7 Comparison of Handle and Value Classes . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2 Basic Difference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2 Behavior of MATLAB Built-In Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2 User-Defined Value Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3 User-Defined Handle Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-4 Determining Equality of Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-6 Functionality Supported by Handle Classes . . . . . . . . . . . . . . . . . . . . . . . 7-7 Which Kind of Class to Use . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-9 Examples of Value and Handle Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-9 When to Use Value Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-9 When to Use Handle Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-9 The Handle Superclass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-11 Building on the Handle Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-11 Handle Class Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-11 Event and Listener Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-11 Relational Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-12 Test Handle Validity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-12 When MATLAB Destroys Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-12 Handle Class Destructor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-13 Basic Knowledge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-13 Syntax of Handle Class Destructor Method . . . . . . . . . . . . . . . . . . . . . . . 7-13 Handle Object During delete Method Execution . . . . . . . . . . . . . . . . . . . 7-14 Support Destruction of Partially Constructed Objects . . . . . . . . . . . . . . . 7-15 When to Define a Destructor Method . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-15 Destructors in Class Hierarchies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-16 Object Lifecycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-16 Restrict Access to Object Delete Method . . . . . . . . . . . . . . . . . . . . . . . . . 7-17 Nondestructor Delete Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-18 External References to MATLAB Objects . . . . . . . . . . . . . . . . . . . . . . . . . 7-18 Find Handle Objects and Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-21 Find Handle Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-21 Find Handle Object Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-21 Implement Set/Get Interface for Properties . . . . . . . . . . . . . . . . . . . . . . . 7-22 The Standard Set/Get Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-22 Subclass Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-22 Get Method Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-22 Set Method Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-23 Class Derived from matlab.mixin.SetGet . . . . . . . . . . . . . . . . . . . . . . . . . 7-23 ix Set Priority for Matching Partial Property Names . . . . . . . . . . . . . . . . . . 7-27 Implement Copy for Handle Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-30 Copy Method for Handle Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-30 Customize Copy Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-31 Copy Properties That Contain Handles . . . . . . . . . . . . . . . . . . . . . . . . . . 7-32 Exclude Properties from Copy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-33 Properties — Storing Class Data 8 Ways to Use Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2 What Are Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2 Types of Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2 Property Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-4 Property Definition Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-4 Access Property Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-5 Inheritance of Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-5 Specify Property Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-5 Property Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-6 Purpose of Property Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-6 Specifying Property Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-6 Table of Property Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-6 Property Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-12 What You Can Define . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-12 Initialize Property Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-12 Property Default Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-13 Initializing Properties to Handle Objects . . . . . . . . . . . . . . . . . . . . . . . . . 8-13 Assign Property Values in Constructor . . . . . . . . . . . . . . . . . . . . . . . . . . 8-14 Property Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-15 Methods to Set and Get Property Values . . . . . . . . . . . . . . . . . . . . . . . . . 8-15 Reference Object Properties Using Variables . . . . . . . . . . . . . . . . . . . . . 8-16 Mutable and Immutable Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-17 Set Access to Property Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-17 Define Immutable Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-17 Validate Property Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-19 Property Validation in Class Definitions . . . . . . . . . . . . . . . . . . . . . . . . . 8-19 Sample Class Using Property Validation . . . . . . . . . . . . . . . . . . . . . . . . . 8-20 Order of Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-21 Abstract Property Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-22 Objects Not Updated When Changing Validation . . . . . . . . . . . . . . . . . . . 8-22 Validation During Load Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-22 Property Class and Size Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-24 Property Class and Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-24 Property Size Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-24 Property Class Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-25 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.