| Programming and Data Types | ![]() |
Defining end Indexing for an Object
When you use end in an object indexing expression, MATLAB calls the object's end class method. If you want to be able to use end in indexing expressions involving objects of your class, you must define an end method for your class.
The end method has the calling sequence
where a is the user object, k is the index in the expression where the end syntax is used, and n is the total number of indices in the expression.
For example, consider the expression
MATLAB calls the end method defined for the object A using the arguments
That is, the end statement occurs in the first index element and there are two index elements. The class method for end must then return the index value for the last element of the first dimension. When you implement the end method for your class, you must ensure it returns a value appropriate for the object.
| Object Indexing Within Methods | Indexing an Object with Another Object | ![]() |