0
我一直在学习MATLAB文档中的类,并注意到他们已经推荐了两种方法来做同样的事情,但我想知道它们之间的区别或者使用它们的优点是。在此,在类的方法部分中,是两种看似-相同功能:在方法中分配有或没有“set”属性的类值的优点?
classdef BasicClass
properties
Value
end
methods
function obj = BasicClass(val)
if (val > 0)
obj.Value = val;
else
error('Value must be numeric')
end
end
function obj = set.Value(obj,val)
if (val > 0)
obj.Value = val;
else
error('Property value must be positive')
end
end
end
end
如何obj = BasicClass(val)
使用obj = set.Value(obj,val)
最终不同?任何指导将不胜感激。