Reputation: 91
I have written the following class for polynomials but i keep getting the error
No public field polynomial exists for class Poly.
Error in Poly (line 13)
obj.polynomial=struct('exponent',{p.exponent},'coeff',{p.coeff});
Here is my class
classdef Poly
properties
polynomial
end
methods
function obj=Poly(p)
if isa(p,'Poly')
obj=p;
else
obj.polynomial=struct('exponent',{p.exponent},'coeff',{p.coeff});
end
end
function answer=plus(obj1,obj2)
obj1=Poly(obj1);
obj2=Poly(obj2);
answer=Poly(addPoly(obj1.polynomial,obj2.polynomial));
end
function answer=mtimes(obj1,obj2)
obj1=Poly(obj1);
obj2=Poly(obj2);
answer=Poly(multPoly(obj1.polynomial,obj2.polynomial));
end
function answer=rem(obj1,obj2)
obj1=Poly(obj1);
obj2=Poly(obj2);
answer=Poly(dividePolyrem(obj1.polynomial,obj2.polynomial));
end
end
end
I am unsure why I keep getting this error,I have tried adding (SetAccess=Public)
after properties
but that didn't seem to work. Any suggestions?
Upvotes: 1
Views: 195
Reputation: 36710
Your source code is fine (besides the missing end
for classdef and methods), probably there is an exists an outdated version of the class, which prevents matlab to update the class definition. Clear all variables containing instances of Poly
.
http://www.mathworks.de/de/help/matlab/matlab_oop/modifying-and-reloading-classes.html
Upvotes: 2