Main Content

Reinitialize States of Blocks in Subsystem

The Reinitialize Function block allows you set the state of all blocks in a referenced model or subsystem back to their initial condition, as well as to explicitly set block states or block parameters, at any time during model simulation. This example demonstrates the use of the Reinitialize Function block in a subsystem.

Simulink model including subsystem with reinitialize port

The model contains a subsystem with a reinitialize port. A Function-Call Generator block sends a function-call signal to the port at time step 5.

Inside the subsystem, two Discrete-Time Integrator blocks integrate the input signal and output the result. The blocks are identically configured, with the Initial condition set to 0.

Subsystem containing Reinitialize Function block and 2 Discrete-Time Integrator blocks connected to a branched input signal.

The subsystem contains a Reinitialize Function block. Inside the Reinitialize Function block is a State Writer block that is configured to set the state of one of the two Discrete-Time Integrator blocks to 10.

Event Listener block and Constant block connected to State Writer block.

The Reinitialize Function block executes only when the subsystem receives a reinitialize event, that is, when a function-call event is set to the reinitialize port of the subsystem. To expose a reinitialize port on the subsystem block, in the Subsystem block parameters dialog box, select Treat as atomic unit and then select Show subsystem reinitialize ports.

Subsystem block parameters dialog box. Parameters 'Treat as atomic unit' and 'Show subsystem reinitialize ports' are highlighted.

Note

You can also use the Reinitialize Function block inside conditional subsystems. In such cases, you do not need to select Treat as atomic unit.

A port is displayed on the Subsystem block with the reinitialize icon reinitialize icon and the label reinit. This label corresponds to the Event name specified in the Event Listener block inside the Reinitialize Function block.

Subsystem block with reinitialize port. Port is highlighted.

Sending a function-call event to the reinitialize port generates a subsystem reinitialize event, which has these effects:

  1. For each block with a state in the subsystem, the state is set to the initial condition, as specified in the block parameters. In this example, the states of both Discrete-Time Integrator blocks are set to 0.

  2. The contents of the Reinitialize Function block corresponding to the port are executed. In this example, the State Writer block sets the state of one of the Discrete-Time Integrator blocks to 10, overriding the value set in the previous step.

Note

In addition to or instead of using State Writer blocks to set block states, you can configure a Reinitialize Function block to take other actions, such as setting a block parameter value with a Parameter Writer block or setting a data store value with a Data Store Write block.

In this example, a constant value of 5 is sent to both Discrete-Time Integrator blocks and integrated, and a function-call event is sent to the reinitialize port at time step 5, generating a subsystem reinitialize event. After you simulate the model, the Scope output shows that the first signal is reset to 10 and the second signal is reset to 0 at time step 5.

Scope output showing 2 signals on 2 plots.

See Also

| | | | | | |

Related Topics