This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Class: matlab.System
Package: matlab

Initialize System object




setupImpl(obj) implements one-time tasks. You typically use setupImpl to set private properties so they do not need to be calculated each time stepImpl method is called. To acquire resources for a System object™, you must use setupImpl instead of a constructor.

setupImpl executes the first time the System object is run after that object has been created. It also executes the next time the object is run after an object has been released.

setupImpl(obj,input1,input2,...) sets up a System object using one or more of the stepImpl input specifications. The number and order of inputs must match the number and order of inputs defined in the stepImpl method. You pass the inputs into setupImpl to use the specifications, such as size and data types in the one-time calculations.

setupImpl is called by the setup method, which is done automatically as the first subtask of the running an unlocked System object.


You can omit this method from your class definition file if your System object does not require any setup tasks.

You must set Access = protected for this method.

Do not use setupImpl to initialize or reset states. For states, use the resetImpl method.

You cannot modify any tunable properties in this method if its System object will be used in the Simulink® MATLAB System block.

Input Arguments


System object handle


Inputs to the stepImpl method


expand all

This example shows how to open a file for writing using the setupImpl method in your class definition file.

methods (Access = protected)
   function setupImpl(obj)
      obj.pFileID = fopen(obj.Filename,'wb');
      if obj.pFileID < 0
         error('Opening the file failed');

This example shows how to use setupImpl to specify that running the object initializes the properties of an input. In this case, calls to run the object, which includes input u, initialize the object states in a matrix of size u.

methods (Access = protected)
   function setupImpl(obj, u) 
    obj.State = zeros(size(u),'like', u); 


To validate properties or inputs use the validatePropertiesImpl, validateInputsImpl, or setProperties methods. Do not include validation in setupImpl.

Do not use the setupImpl method to set up input values.

Was this topic helpful?