我为多项式编写了以下类,但我不断收到错误
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
我不确定为什么我一直收到此错误,我尝试在(SetAccess=Public)
之后添加properties
,但这似乎不起作用。有什么建议吗?
答案 0 :(得分:2)
您的源代码很好(除了缺少{class 1和classdef和{1}}之外),可能存在一个过时的类版本,这会阻止matlab更新类定义。清除包含end
实例的所有变量。
http://www.mathworks.de/de/help/matlab/matlab_oop/modifying-and-reloading-classes.html