Using the polynomial class example in the documentation, I have created a class @polynom. Within this class, I have defined a number of methods, one of which is SUBSREF. When I call any overloaded method from within a method of the polynom class, I do not run into any problems. MATLAB knows to look in the class for the method first.
I then try to subsref into my object and instead of calling the overloaded SUBSREF, MATLAB attempts to call the built-in SUBSREF. To work around this I have to explicity call SUBSREF. I would like to know why this works for all other overloaded methods.
The following is an example of calling an object's subsref from the command line:
>> p = polynom([1 2 3 4])p = x^3 + 2*x^2 + 3*x + 4>> x = 2x = 2>> y=p(x)y = 26
When calling y = p(x) from an overloaded method called plot:
>> plot(p) Warning: Subscript indices must be integer values. > In p:\@polynom\plot.m at line 10 ??? Index into matrix is negative or zero. See release notes on changes to logical indices. Error in ==> p:\@polynom\plot.m On line 10 ==> y = p(x);
To workaround this, I have to call SUBSREF explicitly:
y = polyval(p,x);subs.type = '()';subs.subs = {x};y = subsref(p, subs); %should call subsref here
Best Answer