Be very careful not to get yourself into a recursive situation like the class I posted earlier this month for this Answer does. I would probably make B a Dependent property with a get.B method that accesses the A property. See this documentation page for some information about dependent properties. A couple observations about your class:
- Your default value for the A property does not satisfy the size validation you've listed in your file. Either the default value should be [5; 1] or you should require A to be of size [1 2].
- Your doThing method doesn't make sense to me. As written it would make B out of sync with A. You could have doThing update A then the value of the Dependent property B would also be doubled. [I would not define a set.B method, or if I did I would implement it so it throws a user-friendly error message.]
function obj = doThing(obj)
obj.A = 2*obj.A;
end
Best Answer