Add event object to model object
eventObj = addevent(...'
|Required property to specify a trigger condition. Must be a MATLAB® expression
that evaluates to a logical value. Use the keyword |
|Character vector or a cell array of character vectors, each
of which specifies an assignment of the form |
|Property name for an event object from Property Summary.|
|Property value. For more information on property values, see the property reference for each property listed in Property Summary.|
Event object (
and adds the event to the model (
In the event object, this method assigns a value (
to the property
TriggerCondition, assigns a value
EventFcns, and assigns the
model object (
to the property
Parent. In the model object, this
method appends the event object to the property
When the trigger expression in the property
from false to true, the assignments in
executed during simulation.
For details on how events are handled during a simulation, see Events in SimBiology Models.
eventObj = addevent(...' defines
optional properties. The property name and property value pairs can
be any format supported by the function
|Active||Indicate object in use during simulation|
|Name||Specify name of object|
|Notes||HTML text describing SimBiology object|
|Parent||Indicate parent object|
|Tag||Specify label for SimBiology object|
|Type||Display SimBiology object type|
|UserData||Specify data to associate with object|
Add an Event
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 a 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); sbioplot(sd);
Version HistoryIntroduced in R2007b
R2022b: Having duplicate model component names issues a warning
SimBiology issues a warning if multiple model components (model, compartment, species, parameter, reaction, rule, event, observable, dose, and variant) have the same name. In a future release, within a single model, these components will be required to have unique names even when they are of different types with the following two exceptions:
Species in different compartments can have the same name.
Parameters can have the same name if they are scoped to different parents. Specifically, you can use the same name for a model-scoped parameter and reaction-scoped parameters, where each reaction-scoped parameter belongs to a different reaction.
The purpose of this naming restriction is to ensure that every model component can be unambiguously referenced by its unique name within a model. For details on how to reference model component names in expressions, see Guidelines for Referencing Names in Expressions.
To disambiguate duplicate names from your model, use the
updateDuplicateNamesfunction at the command line. The function takes in a SimBiology model as an input and updates the component names as necessary. You can also specify optional outputs, such as a logical flag to check whether any update occurred, a list of model changes, and a copy of the original model before any updates were made.
updateDuplicateNamesfunction disambiguates the duplicate names by adding a suffix
"_N", where N is the first positive integer that results in a unique name. If there is an existing suffix, N will be incremented from that suffix. For example, if there are two model components named x_3, the function updates one of the names to x_4. If the existing suffix has leading zeros, the function omits the zeros in the new name. For instance, if x_003 is a duplicate name, it gets renamed to x_4. However, the function assumes that names with leading zeros and without leading zeros are different. For instance, x_005 and x_5 are considered to be different names.
R2022a: Having duplicate model component names will not be allowed in a future release
SimBiology will not allow you to have duplicate names for model components within a model.