MATLAB Object-Oriented Programming
No Conditional Calls to Superclass Constructors Calls to superclass constructors must be unconditional. There can be only one ca ...
end end Zero or More Superclass Arguments To support a syntax that calls the superclass constructor with no arguments, provide t ...
Implicit Call to Inherited Constructor MATLAB passes arguments implicitly from a default subclass constructor to the superclass ...
MATLAB calls the delete method on the object, the delete methods for any objects contained in properties, and the delete methods ...
See Also Related Examples “Simplifying the Interface with a Constructor” on page 3-22 “Subclass Constructor Implementation” on ...
Static Methods In this section... “What Are Static Methods” on page 9-32 “Why Define Static Methods” on page 9-32 “Defining Stat ...
end end end Calling Static Methods Invoke static methods using the name of the class followed by dot (.), then the name of the m ...
Overload Functions in Class Definitions In this section... “Why Overload Functions” on page 9-34 “Implementing Overloaded MATLAB ...
Perform the necessary steps in the method to implement the function. For example, access the object properties to manipulate da ...
y = rand(1,10); md = MyData(y); Call the method using the object: bar(md) You can also use dot notation: md.bar Implementing MAT ...
See Also Related Examples “Dominant Argument in Overloaded Graphics Functions” on page 9-49 “Class Support for Array-Creation F ...
Class Support for Array-Creation Functions In this section... “Extend Array-Creation Functions for Your Class” on page 9-38 “Whi ...
p = MyClass(...); zArray = zeros(size(p),'like',p); MATLAB uses these arguments to dispatch to the appropriate method in your cl ...
Class Name Method Called If Prototype Method Does Not Exist If your class implements a class name syntax, but does not implement ...
... end end How MATLAB Interprets the Function Call The special support for array-creation functions results from the interpreta ...
zeros(varargin) for “class name” methods zeros(obj,varargin) for “like prototype object” methods Sample Class The Color class ...
function z = zeros(varargin) if (nargin == 0) % For zeros('Color') z = Color; elseif any([varargin{:}] <= 0) % For zeros with ...
dims = [varargin{2:end}]; r = zeros(dims,'Color'); for k = 1:prod(dims) r(k) = Color('RGB',randi(varargin{1},[1,3])); end end en ...
z = repmat(obj,varargin{:}); end end end end Full Class Listing Here is the Color class definition with the overloaded methods. ...
error('Not enough input arguments') end dims = [varargin{2:end}]; r = zeros(dims,'Color'); for k = 1:prod(dims) r(k) = Color('RG ...
«
14
15
16
17
18
19
20
21
22
23
»
Free download pdf