1
我已經寫了多項式下面的類,但我不斷收到錯誤MatLab的:Classdef多項式錯誤
No public field polynomial exists for class Poly.
Error in Poly (line 13)
obj.polynomial=struct('exponent',{p.exponent},'coeff',{p.coeff});
這裏是我的類
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
我不確定爲什麼我總是收到此錯誤,我試過在properties
之後加(SetAccess=Public)
,但那似乎不起作用。有什麼建議麼?