Can anyone explain me the following code, please?
myObj = myClass() ; newObj = myObj.Increment() ; disp myObj.Value disp newObj.Value
myClass is defined as follows:
classdef myClass properties Value end methods function self = myClass(self) self.Value = 5 ; end function self = Increment(self) self.Value = self.Value + 1 ; end end end
Here myObj.Value is always 5, and it is not incremented to 6. In all the other languages I know, there is no need to explicitely write
newObj = oldObj.Function()
in order to make actions of .Function effective on the object itself. Is MATLAB working in that way, or there is something I am missing?
Thank you all,
Mike
Best Answer