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.
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.
Create an application file.
Define a class that inherits from the
Create an observer object that derives from this class.
implement the functions you want for your application. This application
comprises your observer.
Open the model.
Create an instance of your class.
Run the model.
For more information about custom visualization, see Create Custom Visualization.
You can use these methods in your derived class implementation of
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.
In the MATLAB® Command Window, select New > Class.
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
properties section, enter the properties for
methods section, implement the functions for
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@simevents.SimulationObserver(modelname); this.mModel = modelname; end
For more information, see Using Custom Visualization for Entities.
Open the model to observe.
At the MATLAB command prompt, to enable the animator for the model:
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 the simulation.
At the MATLAB command prompt, clear the animator from the model. For example: