| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → SimEvents |
| Contents | Index |
| Learn more about SimEvents |
| On this page… |
|---|
Techniques for Observing Events |
The SimEvents debugger can help you observe events and see the relative sequencing of simultaneous events. For details, see Overview of the SimEvents Debugger.
The next table suggests some additional observation techniques that each focus on a particular kind of event. These techniques indicate the simulation time at which events occur but do not indicate relative sequencing of simultaneous events. Key tools are the Instantaneous Event Counting Scope block, Signal Scope block, and Discrete Event Signal to Workspace block. You can also build a discrete event subsystem that counts events and creates a signal, as illustrated in Example: Focusing on Events, Not Values.
| Event | Observation |
|---|---|
| Counter reset | Observe falling edges in the counter block's #d output signal. Alternatively, use a branch line to connect the counter block's input signal to an Instantaneous Event Counting Scope block. |
| Subsystem | Observe sample time hits in any output signal from the subsystem. Alternatively, connect a Discrete Event Signal to Workspace block to any signal inside the subsystem and then observe the times at which the variable in the workspace indicates a sample time hit of the signal. |
| Entity advancement | Observe increases in the #d output signal of the block from which the entity departs. |
| Entity destruction | Observe increases in the #a output signal of the Entity Sink block. The Instantaneous Entity Counting Scope block provides a plot in place of a #a signal. |
| Entity generation | Observe values of the entity generator's pe output signal. Upon an entity generation, pe repeats a previous value of 0 (if the generated entity departs immediately) or increases from 0 to 1 (if the entity cannot depart). |
| Entity request | |
| Function call | If the block issuing the function call provides a #f1 output signal, then observe its increases. Otherwise, configure a Signal-Based Function-Call Event Generator block by enabling the #f1 output port and setting Generate function call only upon to Function call from port fcn; then insert this block between the block issuing the function call and the block reacting to the function call. |
| Gate (opening or closing) | Use a branch line to connect the Enabled Gate block's en input signal to an Instantaneous Event Counting Scope block. Rising trigger edges of the input signal indicate gate-opening events, while falling trigger edges of the input signal indicate gate-closing events. |
| Memory read | Observe sample time hits in the Signal Latch block's out output signal. |
| Memory write | Observe sample time hits in the Signal Latch block's mem output signal. |
| Port selection | If the block has a p input signal, use a branch line to connect the p signal to an Instantaneous Event Counting Scope block, configured to plot value changes. For the Input Switch or Output Switch block, an alternative is to observe the block's last output signal. |
| Preemption | Observe increases in the #p output signal of the server block. |
| Release | Use a branch line to connect the block's input signal to an Instantaneous Event Counting Scope block. |
| Sample time hit | Use a branch line to connect the signal to an Instantaneous Event Counting Scope block. |
| Service completion | Observe values of the server's #pe (or pe in the case of the Single Server block) output signal. Upon a service completion, the signal repeats a previous value of 0 (if the entity departs immediately) or increases (if the entity cannot depart). Because simultaneous repeated values would not be easy to observe on a plot, it is best to observe the signal value in the MATLAB workspace if a departure and a new service completion might occur simultaneously in your model. |
| Storage completion | Observe values of the switch's pe output signal. Upon a storage completion event, the signal repeats a previous value of 0 (if the entity departs immediately) or increases (if the entity cannot depart). Because simultaneous repeated values would not be easy to observe on a plot, it is best to observe the signal value in the MATLAB workspace if a departure and a new storage completion might occur simultaneously in your model. |
| Timeout | Observe increases in the #to output signal of the storage block from which the entity times out. |
| Trigger | Use a branch line to connect the signal to an Instantaneous Event Counting Scope block. |
| Value change | Use a branch line to connect the signal to an Instantaneous Event Counting Scope block. |
For examples that use one or more of these techniques, see
Also, Example: Detecting Collisions by Comparing Events shows how to use a Signal Latch block to observe which of two types of events occurred more recently.
The example below (open model) writes an N-Server block's #pe signal to a structure called pe in the MATLAB workspace. In the structure, pe.time indicates when each value is attained and pe.signals.values indicates the corresponding value.

An entity completes its service at precisely those times when the #pe signal repeats its previous value or increases to a larger value. After the simulation is over, you can form a vector of service completion times using the code below.
% Output #pe times and values. pe_matrix = [pe.time, pe.signals.values] % Determine when #pe changes its value. dpe = [0; diff(pe.signals.values)]; % Service completions occur when #pe does not decrease. t_svcp = pe.time(dpe >= 0)
Sample output, which depends on the entity generation, service completion, gate opening, and gate closing times in the model, is below. Notice the rows of pe_matrix in which the first column is 2.0000 and the second column has decreasing values. These correspond to decreases in the #pe signal value at T=2, which result from departures of entities that completed their service at an earlier time. The value T=2 does not appear in the t_svcp vector because this is not a time at which service completion events occur.
pe_matrix =
0.4542 1.0000
0.9077 2.0000
1.1218 3.0000
1.3868 4.0000
2.0000 3.0000
2.0000 2.0000
2.0000 1.0000
2.0000 0
2.3430 0
2.3570 0
2.9251 0
2.9370 0
3.5592 0
4.3933 0
4.8554 1.0000t_svcp =
0.4542
0.9077
1.1218
1.3868
2.3430
2.3570
2.9251
2.9370
3.5592
4.3933
4.8554The example below (open model) aims to determine whether an entity is the only entity in an infinite server for the entire duration of service. The model uses the Signal Latch block to compare the times of two kinds of events and report which kind occurred more recently. This usage of the Signal Latch block relies on the block's status output signal, st, rather than the default in and out ports.

In the model, entities arrive at an infinite server, whose #n output signal indicates how many entities are in the server. The Signal Latch block responds to these signal-based events involving the integer-valued #n signal:
If #n increases from 0 to a larger integer, then
rtr has a rising edge.
The Signal Latch block processes a read event.
The Signal Latch block's st output signal becomes 0.
If #n increases from 1 to a larger integer, then
wtr has a rising edge.
The Signal Latch block processes a write event.
The Signal Latch block's st output signal becomes 1.
If #n increases from 0 to 2 at the same value of the simulation clock, then it also assumes the value 1 as a zero-duration value. As a result,
rtr and wtr both have rising edges, in that sequence.
The Signal Latch block processes a read event followed by a write event.
The Signal Latch block's st output signal becomes 1.
By the time the entity departs from the Infinite Server block, the Signal Latch block's st signal is 0 if and only if that entity has been the only entity in the server block for the entire duration of service. This outcome is considered a success for that entity. Other outcomes are considered collisions between that entity and one or more other entities.
This example is similar to the CSMA/CD subsystem in the Ethernet Local Area Network demo.
![]() | Example: Event Calendar Usage for a Queue-Server Model | Generating Function-Call Events | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |