MATLAB Object-Oriented Programming
See Also Related Examples “Create a Simple Class” on page 2-2 “Developing Classes — Typical Workflow” on page 3-8 “Representing ...
Developing Classes — Typical Workflow In this section... “Formulating a Class” on page 3-8 “Specifying Class Components” on page ...
that are designed to listen for these notices. In this example, a simplified version of an account manager program performs this ...
AccountListener — Storage for the InsufficentFunds event listener. Saving a BankAccount object does not save this property beca ...
BankAccount Class Synopsis BankAccount Class Discussion classdef BankAccount < handle Handle class because there should be on ...
BankAccount Class Discussion function BA = BankAccount(AccountNumber,InitialBalance) BA.AccountNumber = AccountNumber; BA.Accoun ...
BankAccount Class Discussion function obj = loadobj(s) if isstruct(s) accNum = s.AccountNumber; initBal = s.AccountBalance; obj ...
end newbal = BA.AccountBalance - amt; BA.AccountBalance = newbal; if newbal < 0 notify(BA,'InsufficientFunds') end end functi ...
assignStatus — Method that assigns a status to a BankAccount object. Serves as the listener callback. addAccount — Method that ...
AccountManager Class Discussion function assignStatus(BA) if BA.AccountBalance < 0 if BA.AccountBalance < -200 BA.AccountS ...
Using BankAccount Objects The BankAccount class, while overly simple, demonstrates how MATLAB classes behave. For example, creat ...
------------------------- Account: 1234567 CurrentBalance: -300.00 Account Status: closed ------------------------- Now the Acco ...
Representing Structured Data with Classes In this section... “Objects as Data Structures” on page 3-19 “Structure of the Data” o ...
Data Description Material char vector identifying the type of material tested SampleNumber Number of a particular test sample St ...
Advantages of a Class vs. a Structure Treat the TensileData object (td in the previous statements) much as you would any MATLAB ...
end methods function obj = set.Material(obj,material) if (strcmpi(material,'aluminum') ||... strcmpi(material,'stainless steel') ...
td.Stress = stress; td.Strain = strain; end end end Create a TensileData object fully populated with data using the following st ...
Define the property get method in a methods block using only default attributes. methods function modulus = get.Modulus(obj) ind ...
The disp method uses fprintf to display formatted text in the command window: methods function disp(td) fprintf(1,... 'Material: ...
TensileData Class Synopsis Example Code Discussion classdef TensileData Value class enables independent copies of object. For mo ...
«
1
2
3
4
5
6
7
8
9
10
»
Free download pdf