MATLAB: Class properties are being reinitialized each time I call a method

classconstructormethodobjectoop

Hi, class properties are being reinitialized each time I call a method. the result of the multiplication is always 15. Could you please tell me where is the error? I don't want to use any argument in the constructor method.
classdef Multi
properties
x = 0;
y = 0;
end
methods
function obj = Multi()
obj.x = 5;
obj.y = 3;
end
function obj = X (obj, x)
obj.x = x;
end
function obj = Y (obj, y)
obj.y = y;
end
function obj = Mul (obj)
disp (obj.x * obj.y);
end
end
end

Best Answer

You've shown the class definition, but not your test code. So, the problem appears to be entirely in your imagination:
>> obj=obj.X(20);
>> obj=obj.Y(10);
>> obj.Mul;
200
However, I suspect that you neglected to assign the output of obj.X() and obj.Y() as above. If you don't want to have to do that, you might consider making this a handle class.