%% Add an Event
% 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);
sbioplot(sd);

% Copyright 2015 The MathWorks, Inc.