定义 System object 信息
此示例说明如何为 System object™ 定义要显示的信息。
定义 System object 信息
您可以定义您自己的 info
方法,以显示您的 System object 的特定信息。默认的 infoImpl
方法会返回一个空结构体。使用 info(x,'details')
调用 info
时,此 infoImpl
方法将返回详细信息;使用 info(x)
调用时,则仅返回计数信息。
methods (Access = protected) function s = infoImpl(obj,varargin) if nargin>1 && strcmp('details',varargin(1)) s = struct('Name','Counter', 'Properties', struct('CurrentCount',obj.Count, ... 'Threshold',obj.Threshold)); else s = struct('Count',obj.Count); end end end
使用 InfoImpl
完成类定义文件
classdef Counter < matlab.System % Counter Count values above a threshold properties Threshold = 1 end properties (DiscreteState) Count end methods (Access = protected) function setupImpl(obj) obj.Count = 0; end function resetImpl(obj) obj.Count = 0; end function y = stepImpl(obj,u) if (u > obj.Threshold) obj.Count = obj.Count + 1; end y = obj.Count; end function s = infoImpl(obj,varargin) if nargin>1 && strcmp('details',varargin(1)) s = struct('Name','Counter',... 'Properties', struct('CurrentCount', ... obj.Count,'Threshold',obj.Threshold)); else s = struct('Count',obj.Count); end end end end