Define System Object Information - MATLAB & Simulink (original) (raw)
This example shows how to define information to display for a System objectâ„¢.
Define System Object Info
You can define your own info
method to display specific information for your System object. The default infoImpl
method returns an empty struct. ThisinfoImpl
method returns detailed information wheninfo
is called using info(x,'details')
or only count information if it is called using 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
Complete Class Definition File with 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