MATLAB Object-Oriented Programming
See “Class Attributes” on page 6-6 for a list of attributes and a discussion of the behaviors they control. Superclass Syntax De ...
Properties In this section... “The Properties Block” on page 5-12 “Access to Property Values” on page 5-13 The Properties Block ...
classdef NewCar properties Model Color end properties (SetAccess = private) SerialNumber end methods ... end end Access to Prope ...
obj.Model = model; obj.Color = color; obj.SerialNumber = datenum(datetime('now')); end end end A = NewCar('XGT7000','Red') A = N ...
Methods and Functions In this section... “The Methods Block” on page 5-15 “Method Calling Syntax” on page 5-15 “Private Methods” ...
The left most argument does not need to be the class object, and the argument list can have multiple objects. MATLAB dispatches ...
Call staticMethod using the syntax classname.methodname: r = MyClass.staticMethod(arg1); See “Static Methods” on page 9-32 for i ...
function myUtilityFcn ... end You also can create package functions, which require the use of the package name when calling thes ...
Property set and get access methods For more information on defining methods in separate files, see “Methods in Separate Files ...
Events and Listeners In this section... “Define and Trigger Events” on page 5-20 “Listen for Events” on page 5-20 Define and Tri ...
See Also event.hasListener | event.listener | event.proplistener Related Examples “Overview Events and Listeners” on page 11-2 ...
Attribute Specification In this section... “Attribute Syntax” on page 5-22 “Attribute Descriptions” on page 5-22 “Attribute Valu ...
Attribute Values When you specify attribute values, those values affect all the components defined within the defining block. Fo ...
Use the not operator before an attribute name to define it as false: methods (~Static) ... end Is the same as: methods (Static = ...
Call Superclass Methods on Subclass Objects In this section... “Superclass Relation to Subclass” on page 5-25 “How to Call Super ...
classdef MySub < MySuperClass methods function disp(obj) disp@MySuperClass(obj) ... end end end How to Call Superclass Constr ...
end end end See “Subclass Constructors” on page 9-26 for more information. See Also Related Examples “Modify Inherited Methods” ...
Representative Class Code In this section... “Class Calculates Area” on page 5-28 “Description of Class Definition” on page 5-31 ...
function plot(obj) r = obj.Radius; d = r*2; pos = [0 0 d d]; curv = [1 1]; rectangle('Position',pos,'Curvature',curv,... 'FaceCo ...
Query the area of the defined circle: ca.Area ans = 164.2202 Call the overloaded plot method: plot(ca) 5 Class Definition—Syntax ...
«
2
3
4
5
6
7
8
9
10
11
»
Free download pdf