Products & Services Solutions Academia Support User Community Company

Learn more about SimEvents   

Sending Data to the MATLAB Workspace

Behavior of the Discrete Event Signal to Workspace Block

The Discrete Event Signal to Workspace block writes event-based signals to the MATLAB workspace when the simulation stops or pauses. One way to pause a running simulation is to select Simulation > Pause. When inside a discrete event subsystem, the To Workspace block can also be useful for writing event-based signals to the MATLAB workspace.

Example: Sending Queue Length to the Workspace

The example below (open model) shows one way to write the times and values of an event-based signal to the MATLAB workspace. In this case, the signal is the #n output from a FIFO Queue block, which indicates how many entities the queue holds.

After you run this simulation, you can use the following code to create a two-column matrix containing the time values in the first column and the signal values in the second column.

times_values = [num_in_queue.time, num_in_queue.signals.values]

The output below reflects the Time-Based Entity Generator block's constant intergeneration time of 0.8 second and the Single Server block's constant service time of 1.1 second.

times_values =

         0         0
    0.8000    1.0000
    1.1000         0
    1.6000    1.0000
    2.2000         0
    2.4000    1.0000
    3.2000    2.0000
    3.3000    1.0000
    4.0000    2.0000
    4.4000    1.0000
    4.8000    2.0000
    5.5000    1.0000
    5.6000    2.0000
    6.4000    3.0000
    6.6000    2.0000
    7.2000    3.0000
    7.7000    2.0000
    8.0000    3.0000
    8.8000    4.0000
    8.8000    3.0000
    9.6000    4.0000
    9.9000    3.0000

From the output, you can see that the number of entities in the queue increases at times that are a multiple of 0.8, and decreases at times that are a multiple of 1.1. At T=8.8, a departure from the server and an entity generation occur simultaneously; both events influence the number of entities in the queue. The output shows two values corresponding to T=8.8, enabling you to see the zero-duration value that the signal assumes at this time.

Using the To Workspace Block with Event-Based Signals

The To Workspace block in the Simulink Sinks library can be useful for working with event-based signals in special ways, such as

If you use the To Workspace block in the Simulink Sinks library to write event-based signals to the MATLAB workspace, you should

  1. Set the block's Save format parameter to Structure With Time, which causes the block to record time values, not just signal values.

  2. Place the To Workspace block in a discrete event subsystem to ensure that the workspace variable records data at appropriate times during the simulation.

For more details about discrete event subsystems, see Role of Discrete Event Subsystems in SimEvents Models.

  


Free Discrete Event Simulation Technical Kit

Model electronic system architectures, process flows, and logistics as queuing systems or agent-based systems.

Get free kit

Trials Available

Try the latest version of discrete-event simulation products.

Get trial software
 © 1984-2010- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS