Main Content

setupImpl

Class:matlab.System

InitializeSystem object

Syntax

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

Description

setupImpl(obj)implements one-time tasks.

setupImpl(obj,input1,input2,...)sets up a System object™ using one or more of thestepImplinput specifications.

Run-Time Details

setupImplis called via thesetupmethod. Users never call thesetupmethod directly. But,setupis called the first time a System object is run and after a System object has been released. For details, seeDetailed Call Sequence

Method Authoring Tips

  • If your System object does not require any setup tasks, you can omit this method from your class definition file.

  • UsesetupImplto set private properties so they do not need to be calculated each timestepImplmethod is called.

  • To acquire resources for a System object, you must usesetupImplinstead of a constructor.

  • You must setAccess = protectedfor this method.

  • Do not usesetupImplto initialize or reset states. For states, use theresetImplmethod.

  • If the System object will be used in the Simulink®MATLAB System(Simulink)block, you cannot modify any tunable properties in thesetupImplmethod

  • Do not use thesetupImplmethod to set up input values.

  • Do not include validation insetupImpl. To validate properties or inputs use thevalidatePropertiesImpl,validateInputsImpl, ormethods.

Input Arguments

expand all

System object handle used to access properties, states, and methods specific to the object. If yoursetupImplmethod does not use the object, you can replace this input with~.

List the inputs to the System object. The order of inputs must match the order of inputs defined in thestepImplmethod.stepImplpasses the inputs intosetupImplto use the specifications, such as size and data types in the one-time calculations.

Examples

expand all

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

methods (Access = protected)functionsetupImpl(obj) obj.pFileID = fopen(obj.Filename,'wb');ifobj.pFileID < 0 error('Opening the file failed');endendend

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

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

版本历史

Introduced in R2011b