function obj = SimpleHandleClass(c)
if nargin > 0
obj.Color = c;
end
end
end
end
Create an instance of SimpleHandleClass, assigning a value of red to its Color
property:
obj = SimpleHandleClass('red');
Pass the object to the function g, which assigns blue to the Color property:
y = g(obj);
The function g sets the Color property of the object referred to by both the returned
handle and the original handle:
y.Color
ans =
blue
obj.Color
ans =
blue
The variables y and obj refer to the same object:
y.Color = 'yellow';
obj.Color
ans =
yellow
The function g modified the object referred to by the input argument (obj) and returned
a handle to that object in y.
5 Class Definition—Syntax Reference