Reset Algorithm and Release Resources - MATLAB & Simulink (original) (raw)
Main Content
Reset Algorithm State
When a user calls reset on a System object, the internalresetImpl
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 release is called on a System object, the internal releaseImpl
method is called if step
orsetup
was previously called (see Summary of Call Sequence). 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.
This method allows you to clear the axes on the Whiteboard figure window while keeping the figure open.
function releaseImpl(obj) cla(Whiteboard.getWhiteboard()); hold on end
For a complete definition of the Whiteboard
System object, see Create a Whiteboard System Object.