This example shows how to reset an object state.
Reset Counter to Zero
pCount is an internal counter property
of the System object™
obj. The user calls the
on the locked object, which calls the
In this example ,
pCount resets to 0.
Note: When resetting an object's state, make sure you reset the size, complexity, and data type correctly.
methods (Access = protected) function resetImpl(obj) obj.pCount = 0; end end
Complete Class Definition File with State Reset
classdef Counter < matlab.System % Counter System object that increments a counter properties (Access = private) pCount end methods (Access = protected) % In step, increment the counter and return % its value as an output function c = stepImpl(obj) obj.pCount = obj.pCount + 1; c = obj.pCount; end % Reset the counter to zero. function resetImpl(obj) obj.pCount = 0; end end end
See Methods Timing for more information.