Programming Previous page   Next Page

Object Indexing Within Methods

If a subscripted reference is made within a class method, MATLAB uses its built-in subsref function to access data within the method's own class. If the method accesses data from another class, MATLAB calls the overloaded subsref function in that class. The same holds true for subscripted assignment and subsasgn.

The following example shows a method, testref, that is defined in the class, employee. This method makes a reference to a field, address, in an object of its own class. For this, MATLAB uses the built-in subsref function. It also references the same field in another class, this time using the overloaded subsref of that class.

The example creates an employee object and a company object.

The employee class method, testref, is called. MATLAB uses an overloaded subsref only to access data outside of the method's own class.


Previous page  Handling Subscripted Assignment Defining end Indexing for an Object Next page

© 1994-2005 The MathWorks, Inc.