MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Reset Algorithm and Release Resources


In this section...
“Reset Algorithm State” on page 34-30
“Release System Object Resources” on page 34-30

Reset Algorithm State


When a user calls reset on a System object, the internal resetImpl method is called. In
this example, pCount is an internal counter property of the Counter System object.
When a user calls reset, pCount resets to 0.

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

Release System Object Resources


When a user calls release on a System object, the internal releaseImpl method is
called. This example shows how to implement the method that releases resources
allocated and used by the System object. These resources include allocated memory and
files used for reading or writing.

34 System object Usage and Authoring

Free download pdf