MATLAB: MATLAB OOP question.

MATLABoopself reference

OK possibly a silly question, be please read and help me out regardless. 🙂
Does an object have a sense of self?
What I mean is, let's say I want to have some method which you call that increases a protected property by 1.
So you call the method: MyObj.AddOneToThatThingyMaBob().
Inside the method, what do I use as a subsitute for "this" like you would use in C#? AKA in C# it might be something similar to: this.MyValue = this.MyValue + 1;
How do you do that in MATLAB?

Best Answer

In MATLAB, a method would typically have a signature:
classdef test1234 < handle
properties (Access = public)
prop
end
methods
function obj = test1234()
obj.prop =0;
end
function AddOneToThatThing(obj)
obj.prop = obj.prop+1;
end
end
end
Then
a = test1234;
a.AddOneToThatThing();
a
Gives you what you need. The key here is Handle classes
Related Question