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.

Define Finite Source Objects

This example shows how to define a System object™ that performs a specific number of steps or specific number of reads from a file.

Use the FiniteSource Class and Specify End of the Source

  1. Subclass from finite source class.

     classdef RunTwice < matlab.System & ...
        matlab.system.mixin.FiniteSource
    
  2. Specify the end of the source with the isDoneImpl method. In this example, the source has two iterations.

     methods (Access = protected)
       function bDone = isDoneImpl(obj)
          bDone = obj.NumSteps==2
       end
    

Complete Class Definition File with Finite Source

classdef RunTwice < matlab.System & ...
    matlab.system.mixin.FiniteSource
  % RunTwice System object that runs exactly two times
  %  
  properties (Access = private)
    NumSteps
  end
  
  methods (Access = protected)
    function resetImpl(obj)
      obj.NumSteps = 0;
    end

    function y = stepImpl(obj)
      if ~obj.isDone()
        obj.NumSteps = obj.NumSteps + 1;
        y = obj.NumSteps;
      else
        y = 0;
      end
    end

    function bDone = isDoneImpl(obj)
      bDone = obj.NumSteps==2;
    end
  end
end

See Also

More About

Was this topic helpful?