Main Content

Use SimulationObserver Class to Monitor a SimEvents Model

SimulationObserver Class

To create an observer, create a class that derives from the simevents.SimulationObserver object. You can use observers to:

  • Help understand queue impact, visualize entities moving through the model during simulation,

  • Develop presentation tools showing model simulation via an application-oriented interface, such as restaurant queue activity.

  • Debug and examine entity activity.

  • Examine queue contents.

The simevents.SimulationObserver object provides methods that let you:

  • Create observer or animation objects.

  • Identify model blocks for notification of run-time events.

  • Interact with the event calendar.

  • Perform activities when a model pauses, continues after pausing, and terminates.

SimEvents® models call these functions during model simulation.

Custom Visualization Workflow

  1. Create an application file.

    1. Define a class that inherits from the simevents.SimulationObserver class.

    2. Create an observer object that derives from this class.

    3. From the simevents.SimulationObserver methods, implement the functions you want for your application. This application comprises your observer.

  2. Open the model.

  3. Create an instance of your class.

  4. Run the model.

For more information about custom visualization, see Create Custom Visualization.

Create an Application

You can use these methods in your derived class implementation of simevents.SimulationObserver.


Specify behavior when simulation starts.


Specify behavior when simulation pauses.


Specify behavior when simulation resumes.


Define observer behavior when simulation is terminating.


Specify list of blocks to be notified of entity entry and exit events.


Specify whether you want notification for all events in the event calendar.


Specify behavior after an entity enters a block that has entity storage.


Specify behavior before an entity exits a block with entity storage.


Specify behavior before execution of an event.


Add block to list of blocks to be notified.


Remove block from list of blocks being notified.


Get handles to event calendars.


Get list of blocks that store entities.


Return block handle for a given block path.


Return storage handles of specified block.


  1. In the MATLAB® Command Window, select New > Class.

  2. In the first line of the file, inherit from the simevents.SimulationObserver class. For example:

    classdef seRestaurantAnimator < simevents.SimulationObserver

    seRestaurantAnimator is the name of the new observer object.

  3. In the properties section, enter the properties for your application.

  4. In the methods section, implement the functions for your application.

  5. To construct the observer object, enter a line like the following in the methods section of the file:

    function this = seRestaurantAnimator
                % Constructor
                modelname = 'seCustomVisualization';
                this.mModel = modelname;

For more information, see Using Custom Visualization for Entities.

Use the Observer to Monitor the Model

  1. Open the model to observe.

  2. At the MATLAB command prompt, to enable the animator for the model:

    >> obj=seRestaurantAnimator;

  3. Simulate the model.

    When the model starts, the animator is displayed in a figure window. As the model runs, it makes calls into your application to see if you have implemented one of the predefined set of functions. If your model does not contain a SimEvents block, you receive an error.


As a result of the instrumentation to visualize the simulation, the simulation is slower than without the instrumentation.

Stop Simulation and Disconnect the Model

  1. Stop the simulation.

  2. At the MATLAB command prompt, clear the animator from the model. For example:

    clear obj;

See Also

Related Topics