Update Sequence for Output Signals

Determining the Update Sequence

When a block produces more than one output signal in response to events, the simulation behavior might depend on the sequence of signal updates relative to each other. This is especially likely if you use one of the signals to influence a behavior or computation that also depends on another one of the signals, as in Example: Detecting Changes in the Last-Updated Signal and Example: Detecting Changes from Empty to Nonempty.

When you turn on more than one output signal from a SimEvents block's dialog box (typically, from the Statistics tab), the block updates each of the signals in a sequence. See the Signal Output Ports table on the block's reference page to learn about the update order:

Example: Detecting Changes in the Last-Updated Signal

The example below (open model) plots the ratio of the queue's current length to the time average of the queue length. The FIFO Queue block produces #n and len signals representing the current and average lengths, respectively. The computation of the ratio occurs in a function-call subsystem that is called when the Signal-Based Event to Function-Call Event block detects a change in #n (as long as len is positive, to avoid division-by-zero warnings). Because the FIFO Queue block updates the len signal before updating the #n signal, both signals are up to date when the value change occurs in the #n signal.

Top-Level Model

Subsystem Contents

If you instead connect the len signal to the Signal-Based Event to Function-Call Event block's vc input port, then the block issues a function call upon detecting a change in the len signal. At that point, the #n value is left over from the block's previous arrival or departure, so the computed ratio is incorrect.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS