% 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
endproperties (Logical)
% Whether to increment the counter
Increment = true
endproperties (DiscreteState)
% Count state variable
Count
endmethods (Access = protected)
% Increment the counter and return its value
% as an outputfunction 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;
end34 System object Usage and Authoring