MATLAB: Cannot find ‘set’ method for …. class

class object-oriented set methodoop

Matlab complains about a set method that has already been defined. The error message is, when I type in the command:
set(a, 'prop1', 1)
"Error using set. Cannot find 'set' method for aSimpleValueClass class".
classdef aSimpleValueClass
properties
prop1
end
methods
function obj = set.prop1(obj, x)
obj.prop1 = x;
end
end
end
Can someone tell me why?

Best Answer

You would need to have defined a method named set for that case. The set.prop1 method is called for the case where you use
a.prop1 = value