In MATLAB object-oriented programming, set and get are the methods of redefining parameter setting and querying function, similar to similar functions in Java. In the way of implementation, there is a little difference. In addition, in the implementation of the way, there is no time to find that MATLAB can be directly like in eclipse to edit the Java code to generate the default method.
Write a simple example demonstrating set and get functionality, creating the following classes:
ClassDef Getsetdemo
Properties
Ge
Shi
Bai
End
Methods
function obj = Getsetdemo (g,s,b)
obj.ge = g;
Obj.shi = s;
Obj.bai = b;
End
function value = get.ge (obj)
value = obj.ge;
End
function value = Get.shi (obj)
value = Obj.shi;
End
function value = Get.bai (obj)
value = Obj.bai;
End
function obj = set.ge (obj,value)
obj.ge = value * 1;
End
function obj = Set.shi (obj,value)
Obj.shi = value * 10;
End
function obj = Set.bai (obj,value)
Obj.bai = value * 100;
End
End
End
Use this class to create an object:
>> GS = Getsetdemo (1,2,3)
GS =
Getsetdemowith Properties:
Ge:1
Shi:20
bai:300
>> gs.ge
Ans =
1
>> Gs.shi
Ans =
20
>> Gs.bai
Ans =
300
by the above results, we can see that the default set and get methods are covered by our own design methods.