Main Content

addevent (model)

Add event object to model object


eventObj = addevent(modelObj, 'TriggerValue', 'EventFcnsValue')
eventObj = addevent(...'PropertyName', PropertyValue...)


modelObjModel object.
TriggerValueRequired property to specify a trigger condition. Must be a MATLAB® expression that evaluates to a logical value. Use the keyword 'time' to specify that an event occurs at a specific time during the simulation. For more information, see Trigger.
EventFcnsValueCharacter vector or a cell array of character vectors, each of which specifies an assignment of the form 'objectname = expression', where objectname is the name of a valid object. Defines what occurs when the event is triggered. For more information, see EventFcns.
PropertyNameProperty name for an event object from Property Summary.
PropertyValueProperty value. For more information on property values, see the property reference for each property listed in Property Summary.


eventObj = addevent(modelObj, 'TriggerValue', 'EventFcnsValue') creates an Event object (eventObj) and adds the event to the model (modelObj). In the event object, this method assigns a value (TriggerValue) to the property TriggerCondition, assigns a value (EventFcnsValue) to the property EventFcns, and assigns the model object (modelObj) to the property Parent. In the model object, this method appends the event object to the property Events.

When the trigger expression in the property Trigger changes from false to true, the assignments in EventFcns are executed during simulation.

For details on how events are handled during a simulation, see Events in SimBiology Models.

eventObj = addevent(...'PropertyName', PropertyValue...) defines optional properties. The property name and property value pairs can be any format supported by the function set.

Property Summary

ActiveIndicate object in use during simulation
EventFcnsEvent expression
NameSpecify name of object
NotesHTML text describing SimBiology object
ParentIndicate parent object
TagSpecify label for SimBiology object
TriggerEvent trigger
TypeDisplay SimBiology object type
UserDataSpecify data to associate with object


collapse all

This example shows how to add an event to a SimBiology model.

Create a simple model with a mass action reaction A -> B, where A and B are species. Also add the reaction rate parameter, p1, with the parameter value of 0.5.

model       = sbiomodel('example');
r1          = addreaction(model,'A -> B');
kl          = addkineticlaw(r1,'MassAction');
p1          = addparameter(model,'p1',0.5);
kl.ParameterVariableNames = 'p1';

Increase the amount of species A to 100 at time = 2. You can do this by adding an event object to the model. You must specify the event trigger (time >= 2), and also the event function, which defines what happens when the event is triggered. In this example, the event function is A = 100.

e1 = addevent(model,'time>=2','A = 100');

Simulate the model, and plot the result.

sd = sbiosimulate(model);

Figure contains an axes. The axes with title States versus Time contains 2 objects of type line. These objects represent A, B.

Introduced in R2007b