Main Content

matlab.System Class

Base class for System objects


matlab.System is the base class for System objects. In your class definition file, you must subclass your object from this base class (or from another class that derives from this base class). Subclassing allows you to use the implementation methods and service methods provided by this base class to build your object. Type this syntax as the first line of your class definition file to directly inherit from the matlab.System base class, where ObjectName is the name of your object:

classdef ObjectName < matlab.System


You must set Access = protected for each matlab.System method you use in your code.

The matlab.System class is a handle class.

Class Attributes


For information on class attributes, see Class Attributes.


expand all




function obj = ObjectName(varargin) constructs an ObjectName System object™ and sets properties from name-value pair inputs.

The System object constructor is a public method in the class file. The method name matches the class name. When you create a System object, the constructor is called to initialize properties to nondefault values. The constructor returns a new System object.

Inside the constructor, call setProperties using one of these syntaxes.


setProperties(obj, nargin, varargin{:}) specifies that properties of the System object are set using Name-Value arguments.


setProperties(obj, nargin, varargin{:}, Prop1, ..., PropN) specifies that properties of the System object are set using Value-only arguments

Tip: Within the body of the constructor, do not assign property values. This practice can cause problems if you use the System object in multiple environments ,such as in a System block, in a MATLAB script, and in generated code. Instead, use default property values or change values inside setupImpl.


collapse all

This example shows how to author a basic System object™ called AddOne.

In MATLAB®, select New > System object > Basic. A new editor window opens with default syntax and comments for a new System object.

Rename the class AddOne. Modify the default template so your class looks like this:

classdef AddOne < matlab.System
% ADDONE Compute an output value that increments the input by one

    methods (Access = protected)
       % Implement algorithm. Calculate y as a function of input x.
       function y = stepImpl(~,x)
          y = x + 1;

Use this object by creating an instance of AddOne and running the object with input.

addingObject = AddOne;
x = 5;
ans = 6

Define a System object constructor that allows name-value pair input arguments.

Define a constructor for name-value pair inputs.

function obj = Counter(varargin)
    % Support name-value pair arguments when constructing object

With this constructor body, create a Counter object using name-value pairs.

myObj = Counter('StartValue',0,'UseIncrement',true);

Define a System object constructor with a value-only input property.

Define a constructor with 'StartValue' as a value-only property input. This constructor also allows name-value inputs.

function obj = Counter(varargin)
    % Support value-only argument for StartValue when instantiating

With this constructor body, create a Counter object using a value-only argument for StartValue and name-value pairs for other properties.

myObj = Counter(0,'UseIncrement',true);

More About

expand all

Version History

Introduced in R2011b