| Programming and Data Types | ![]() |
Object Precedence
Object precedence is a means to resolve the question of which of possibly many versions of an operator or function to call in a given situation. Object precedence enables you to control the behavior of expressions containing different classes of objects. For example, consider the expression
objectA+objectB
Ordinarily, MATLAB assumes that the objects have equal precedence and calls the method associated with the leftmost object. However, there are two exceptions:
inferiorto and superiorto functions.For example, in the section Example - A Polynomial Class the polynom class defines a plus method that enables addition of polynom objects. Given the polynom object p
p = polynom([1 0 -2 -5])
p =
x^3-2*x-5
1 + p
ans =
x^3-2*x-4
calls the polynom plus method (which converts the double, 1, to a polynom object, and then adds it to p). The user-defined polynom class has precedence over the MATLAB double class.
| The Portfolio subsref Method | Specifying Precedence of User-Defined Classes | ![]() |