| SimEvents® | ![]() |
| On this page… |
|---|
For discrete event subsystems that respond to entity departures rather than signal-based events, see Creating Entity-Departure Subsystems.
Building on the conceptual information in Role of Discrete Event Subsystems in SimEvents® Models, this section provides some practical information to help you incorporate Discrete Event Subsystem blocks into your SimEvents® models.
To create discrete event subsystems that respond to signal-based events, follow the procedure below using blocks in the SimEvents Ports and Subsystems library.
Note You cannot create a signal-based discrete event subsystem by selecting blocks and using Edit > Create Subsystem or by converting a time-based subsystem into a discrete event subsystem. If your model already contains the blocks you want to put into a discrete event subsystem, then you can copy them into the subsystem window of a Discrete Event Subsystem block while following the procedure below. |
Drag the Discrete Event Subsystem block from the SimEvents Ports and Subsystems library into your model. Initially, it shows one signal input port Din and one signal output port Dout. Note that these are signal ports, not entity ports, because the subsystem is designed to process signals rather than entities. Furthermore, the signal input ports carry only signals of data type double.

In the model window, double-click the Discrete Event Subsystem block to open the subsystem it represents. Initially, the subsystem contains an inport block connected to an outport block. Note that these are Discrete Event Inport and Discrete Event Outport blocks, which are not the same as the Inport and Outport blocks in the Simulink® Ports & Subsystems library. The subsystem also contains a Subsystem Configuration block, which you should not delete.

A discrete event subsystem must have at least one input that determines when the subsystem executes. To change the number of inputs or outputs to the subsystem, change the number of inport and outport blocks in the subsystem window:
If your subsystem requires an additional input or output, then copy and paste an inport block or outport block in the subsystem window. (Copying and pasting is different from duplicating the inport block, which is not supported.) The figure below shows a pasted inport block.

As a result, the subsystem block at the upper level of your model shows the additional port as appropriate. The figure below shows an additional input port on the subsystem block.

If your subsystem needs no outputs, then select and delete the outport block in the subsystem window. The figure below shows the absence of outport blocks.

As a result, the subsystem block at the upper level of your model omits the output port. The figure below shows the absence of output ports on the subsystem block.

Drag other blocks into the subsystem window as appropriate to build the subsystem. This step is similar to the process of building the top level of your model, except that only certain types of blocks are suitable for use inside the subsystem. See Blocks Inside Discrete Event Subsystems for details.
Configure each of the Discrete Event Inport blocks to indicate when the subsystem should be executed. Each inport block independently determines criteria for executing the subsystem:
To execute the subsystem when the signal corresponding to that inport block exhibits a qualifying signal-based event, select Execute subsystem upon signal-based events and use additional parameters in the dialog box to describe the signal-based event. Note that if the signal is complex, then triggers and value changes cannot serve as qualifying signal-based events.
To have the subsystem use the most recent value of the signal corresponding to that inport block without responding to signal-based events in that signal, clear the Execute subsystem upon signal-based events option.

Blocks in a Discrete Event Subsystem operate in response to signal-based events. Using the dialog box of one or more of the Discrete Event Inport blocks inside the subsystem, you configure the subsystem so that it executes in response to particular types of events. The table indicates the types of events and corresponding values of the Type of signal-based event parameter of the Discrete Event Inport block.
| Event | Value of Type of signal-based event Parameter |
|---|---|
| An update (sample time hit) in a real or complex input signal, even if the updated value is the same as the previous value. | Sample time hit |
| A change in the value of a real input signal.If the signal is a nonscalar array, then the subsystem executes once if any of the positions in the array has a change in value of the kind you specify (Rising, Falling, or Either). For example, a rising value change from [1 2 3] to [1 5 6] calls the subsystem once, not twice. | Change in signal |
| A rising edge or falling edge in a real input signal known as a trigger signal. If the signal is a nonscalar array, then the subsystem executes once if any of the positions in the array has an edge of the kind you specify (Rising, Falling, or Either). | Trigger |
Note To call a subsystem upon an entity departure or upon a function call, see Creating Entity-Departure Subsystems or Using Function-Call Subsystems, respectively. |
Each Discrete Event Inport block can potentially execute the subsystem at most once per sample time hit, regardless of whether the signal is scalar or nonscalar. Distinct Discrete Event Inport blocks can execute the subsystem independently of each other.
For example, in the next schematic, suppose Din is a vector of length 2 that the application updates three times at T=1, and Din1 is a scalar that the application updates four times at T=1. Din causes the subsystem to execute three times, and Din1 independently causes the subsystem to execute four times. As a result, the subsystem executes a total of seven times at T=1.

Here are some points to keep in mind when deciding which type of signal-based event should call your discrete event subsystem:
If you want one of the inport blocks to provide an input signal without affecting the times at which the subsystem executes, then clear the Execute subsystem upon signal-based event check box on that inport block. Depending on your model, preventing unwanted subsystem executions might be an optimization or an important modeling decision that prevents an incorrect computation. See these examples of input signals that do not cause subsystems to execute:
However, always select Execute subsystem upon signal-based event for at least one inport block of the subsystem or else the subsystem will never execute.
Value changes are similar to sample time hits, except that a sample time hit might cause a signal to be updated with the same value. If you expect that calling the subsystem for repeated values of an input signal would produce incorrect numerical results or would be wasteful, then execute the subsystem upon changes in the signal value rather than upon every sample time hit.
The Discrete Event Subsystem block is similar to the ordinary Triggered Subsystem block in the Simulink Ports & Subsystems library. However, the Discrete Event Subsystem block can detect zero-duration values in the input signal, which are signal values that do not persist for a positive duration. (See Working with Multivalued Signals for details on zero-duration values.) Unlike the Triggered Subsystem block, the Discrete Event Subsystem block can detect and respond to a trigger edge formed by a zero-duration value, as well as multiple edges in a single instant of time.
Sample time hits can occur for real or complex signals, while triggers and value changes (increasing or decreasing) are not supported for complex signals.
For more information about signal-based events, see Types of Supported Events.
![]() | Blocks Inside Discrete Event Subsystems | Examples Using Discrete Event Subsystem Blocks | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |