MATLAB OOP question.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Adam
el 20 de Jul. de 2011
Editada: per isakson
el 4 de Sept. de 2020
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?
0 comentarios
Respuesta aceptada
Chirag Gupta
el 20 de Jul. de 2011
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
3 comentarios
Chirag Gupta
el 21 de Jul. de 2011
obj is just a variable name used typically in MATLAB (or by me)! If you prefer you could name it as 'this' instead of 'obj'
Más respuestas (0)
Ver también
Categorías
Más información sobre Software Development Tools en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!