MATLAB Object-Oriented Programming

(Joyce) #1

Because matlab.mixin.SetGet and matlab.mixin.SetGetExactNames derive from
the handle class, your subclass is also a handle class.


Get Method Syntax


The get method returns the value of an object property using the object handle and the
property name. For example, assume H is the handle to an object:


v = get(H,'PropertyName');


If you specify an array of handles with a single property name, get returns the property
value for each object as a cell array of values:


CV = get(H,'PropertyName');


The CV array is always a column regardless of the shape of H.


If you specify a cell array of char vector property names and an array of handles, get
returns a cell array of property values. Each row in the cell corresponds to an object in
the handle array. Each column in the cell corresponds to a property name.


props = {'PropertyName1','PropertyName2'};
CV = get(H,props);


get returns an m-by-n cell array, where m = length(H) and n = length(props).


If you specify a handle array, but no property names, get returns an array of type struct
in which each structure in the array corresponds to an object in H. Each field in each
structure corresponds to a property defined by the class of H. The value of each field is
the value of the corresponding property.


SV = get(H);


If you do not assign an output variable, then H must be scalar.


For an example, see “Using get with Arrays of Handles” on page 7-32.


Set Method Syntax


The set method assigns the specified value to the specified property for the object with
handle H. If H is an array of handles, MATLAB assigns the value to the property for each
object in the array H.


Implement Set/Get Interface for Properties
Free download pdf