重置算法并释放资源
重置算法状态
当用户对 System object 调用 reset
时,将调用内部 resetImpl
方法。在此示例中,pCount
是 Counter
System object™ 的内部计数器属性。当用户调用 reset
时,pCount
重置为 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
释放 System object 资源
当对 System object 调用 release
时,如果以前调用过 step
或 setup
,则调用内部 releaseImpl
方法(请参阅调用序列摘要)。此示例说明如何实现某些方法来释放由 System object 分配和使用的资源。这些资源包括分配的内存和用于读取或写入的文件。
此方法允许您清除白板图窗窗口中的坐标区,同时使图窗保持打开状态。
function releaseImpl(obj) cla(Whiteboard.getWhiteboard()); hold on end
有关 Whiteboard
System object 的完整定义,请参阅创建 Whiteboard System object。