% object is running.
properties (Nontunable)
% The initial value of the counter
InitialValue = 0
end
properties (Nontunable, PositiveInteger)
% The maximum value of the counter
MaxValue = 3
end
properties (Logical)
% Whether to increment the counter
Increment = true
end
properties (DiscreteState)
% Count state variable
Count
end
methods (Access = protected)
% Increment the counter and return its value
% as an output
function c = stepImpl(obj)
if obj.Increment && (obj.Count < obj.MaxValue)
obj.Count = obj.Count + 1;
else
disp(['Max count, ' num2str(obj.MaxValue) ' ,reached'])
end
c = obj.Count;
end
% Setup the Count state variable
function setupImpl(obj)
obj.Count = 0;
end
% Reset the counter to one.
function resetImpl(obj)
obj.Count = obj.InitialValue;
end
34 System object Usage and Authoring