%% Simulate a Model and Scan Parameters with Doses
% This example shows how to simulate and scan a parameter of a radiodecay model while a species is being dosed.
% Load the sample project containing the radiodecay model m1.

sbioloadproject radiodecay;

%
% Create a SimFunction object f specifying parameter Reaction1.c to be scanned and species x as a dosed target.

f = createSimFunction(m1,{'Reaction1.c'},{'x','z'},{'x'});

%
% Define a scalar dose of amount 200 molecules given at three time points (5, 10, and 15 seconds).

dosetime = [5 10 15];
dose = [200 200 200];
u = table(dosetime', dose');
u.Properties.VariableNames = {'Time','Amount'};
u.Properties.VariableUnits = {'second','molecule'};

%
% Define the parameter values for Reaction1.c to scan.

phi = [0.1 0.2 0.5]';

%
% Simulate the model for 20 seconds and plot the results.

sbioplot(f(phi,20,u));

%
% You can also specify different dose amounts at different times.

d1 = table(5,100);
d1.Properties.VariableNames = {'Time','Amount'};
d1.Properties.VariableUnits = {'second','molecule'};
d2 = table(10,300);
d2.Properties.VariableNames = {'Time','Amount'};
d2.Properties.VariableUnits = {'second','molecule'};
d3 = table(15,600);
d3.Properties.VariableNames = {'Time','Amount'};
d3.Properties.VariableUnits = {'second','molecule'};

%
% Simulate the model using these doses and plot the results.

sbioplot(f(phi,20,{d1;d2;d3}));

%
% You can also define a cell array of dose tables.

u = cell(3,1);
dosetime = [5 10 15];
dose = [200 200 200];
u{1} = table(dosetime',dose');
u{1}.Properties.VariableNames = {'Time','Amount'};
u{1}.Properties.VariableUnits = {'second','molecule'};
dosetime2 = [2 6 12];
dose2 = [500 500 500];
u{2} = table(dosetime2', dose2');
u{2}.Properties.VariableNames = {'Time','Amount'};
u{2}.Properties.VariableUnits = {'second','molecule'};
dosetime3 = [3 8 18];
dose3 = [100 100 100];
u{3} = table(dosetime3', dose3');
u{3}.Properties.VariableNames = {'Time','Amount'};
u{3}.Properties.VariableUnits = {'second','molecule'};

%
% Simulate the model using the dose tables and plot results.

sbioplot(f(phi,20,u));

% Copyright 2012 The MathWorks, Inc.