MATLAB Object-Oriented Programming

(Joyce) #1

Built-In Indexing Methods


Built-in classes use specially implemented versions of the subsref, subsasgn, and
subsindex methods to implement indexing. When you index a subclass object, only the
built-in data is referenced (not the properties defined by your subclass).


For example, indexing element 2 in the DocSimpleDouble subclass object returns the
second element in the vector:


sc = DocSimpleDouble(1:10);
a = sc(2)


a =
DocSimpleDouble
double data:
2


The value returned from an indexing operation is an object of the subclass. You cannot
make indexed references if your subclass defines properties, unless your subclass
overrides the default subsref method.


Assigning a new value to the second element in the DocSimpleDouble object operates
only on the superclass data:


sc(2) = 12


sc =
1x10 DocSimpleDouble:
double data:
1 12 3 4 5 6 7 8 9 10


The subsref method also implements dot notation for methods.


Built-In Concatenation Methods


Built-in classes use the functions horzcat, vertcat, and cat to implement
concatenation. When you use these functions with subclass objects of the same type,
MATLAB concatenates the superclass data to form a new object. For example, you can
concatenate objects of the DocSimpleDouble class:


sc1 = DocSimpleDouble(1:10);
sc2 = DocSimpleDouble(11:20);
[sc1,sc2]


Behavior of Inherited Built-In Methods
Free download pdf