MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

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.

In this section...
“Use the FiniteSource Class and Specify End of the Source” on page 34-48
“Complete Class Definition File with Finite Source” on page 34-48

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()
34 System object Usage and Authoring

Free download pdf