Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Reset Algorithm State

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 reset method on the locked object, which calls the resetImpl method. 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)
      % 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.

See Also

More About

Was this topic helpful?