Documentation Center

  • Trials
  • Product Updates

setupImpl

Class: matlab.System
Package: matlab

Initialize System object

Syntax

setupImpl(obj)
setupImpl(obj,input1,input2,...)

Description

setupImpl(obj) sets up a System object™ and implements one-time tasks that do not depend on any inputs to the stepImpl method for this object. To acquire resources for a System object, you must use setupImpl instead of a constructor. setupImpl executes the first time the step method is called on an object after that object has been created. It also executes the next time step is called after an object has been released. You typically use setupImpl to set private properties so they do not need to be calculated each time stepImpl method is called.

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 datatypes in the one-time calculations. You do not use the setupImpl method to set up input values.

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

    Note:   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.

Tips

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

Input Arguments

obj

System object handle

input1,input2,...

Inputs to the stepImpl method

Examples

expand all

Setup a File for Writing

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');
       end
    end
end

Check input size

This examples shows how to use setupImpl to check that the size of a stepImpl method input matches the size of a state property.

properties (Access = private)
     myState = [1 2];
  end
   
  methods (Access = protected)
     function setupImpl(obj,u)
        if any(size(obj.myState) ~= size(u))
           error('Size of "myState" does not match size of input "u"');
        end
     end
    
     function y = stepImpl(obj,u)
        y = obj.myState;
        obj.myState = u;
     end
  end
end

See Also

| |

How To

Was this topic helpful?