MATLAB: Operator overloading: class*number vs number*class

classMATLABoperator overloadingprogramming

Hello,
I've defined a class (lets say vector) and I want to be able to overload the following binary operations
1) >> my_class*number
2) >> number*my_class
I have overloaded mtimes, and then case 1) works (I detect the type of the second operator and proceed accordingly), but case 2) does not. In fact the mtimes function of the class does not get called in case 2).
This may seem as logical, but in cannot figure out a work arround for 2).
How do I program behavior for case 2), that is number*my_class ?.
Thanks,
Javier

Best Answer

Solution:
It seems that it is a question of object precedence when invoking the mtimes defined operator.
Changing the definition of my_Class from
classdef my_Class
to
classdef (InferiorClasses = {?sym}) my_Class
gives precedence to my_Class mtimes method against the one of sym class