Define Basic System Objects
This example shows how to create a basic System object that increments a number by
one. The class definition file used in the example contains the minimum elements required
to define a System object.
Create System Object Class
You can create and edit a MAT-file or use the MATLAB Editor to create your System
object. This example describes how to use the New menu in the MATLAB Editor.
(^1) In MATLAB, on the Editor tab, select New > System Object > Basic. A simple
System object template opens.
(^2) Subclass your object from matlab.System. Replace Untitled with AddOne in the
first line of your file.
classdef AddOne < matlab.System
System objects are composed of a base class, matlab.System and may include one
or more mixin classes. You specify the base class and mixin classes on the first line of
your class definition file.
(^3) Save the file and name it AddOne.m.
Define Algorithm
The stepImpl method contains the algorithm to execute when you run your object.
Define this method so that it contains the actions you want the System object to perform.
(^1) In the basic System object you created, inspect the stepImpl method template.
methods (Access = protected)
function y = stepImpl(obj,u)
% Implement algorithm. Calculate y as a function of input u and
% discrete states.
y = u;
end
end
The stepImpl method access is always set to protected because it is an internal
method that users do not directly call or run.
Define Basic System Objects