Simple objects with nested functions
You can create simple reference objects using nested functions and matlab structures.function obj = counter(c1) obj.decr = @decr; obj.incr = @incr; function c1 = incr c1 = c1 + 1; end function c1 = decr c1 = c1 - 1; end function c1 = get end end
You can then use the returned structure to access the counter
object
% create the counter c = counter(10); % increment; c.incr(); c.incr(); % decrement; c.decr(); % get the value c.get() ans = 11