MATLAB: Simulating multiple model parameterizations using scenarios and simfunctions

scenariosSimBiologysimfunction

Hello,
I'm having trouble simultaneously simulating multiple parameterizations of a model using simfunctions and scenarios, in R2019b. Please refer to the example below. Is there a proper way of doing this? I think I could get around this error be inputting all of the parameterizations when calling 'createSimFunction', but this is not possible in my application because I do not know a priori how many different parameterizations I plan to simulate.
Thank you,
Abed
% The following works:
sbioloadproject('insulindemo','m1');
variants = getvariant(m1);
singleMeal = sbioselect(m1,'Name','Single Meal');
sObj = SimBiology.Scenarios;
add(sObj,'cartesian','variants',variants);
add(sObj,'cartesian','dose',singleMeal);
sObj.verify(m1);
f = createSimFunction(m1,sObj,{'[Plasma Glu Conc]','[Plasma Ins Conc]'},[]);
sd = f(sObj,24);
% But the following triggers an error:
nIndivs = 2; % number of parameterizations (let's pretend each individual has different parameterizations -- although in this example they have the same parameterization).
for iEntry = 1:sObj.NumberOfEntries
sObj = sObj.updateEntry(iEntry,'Content',repmat(sObj.getEntry(iEntry).Content,nIndivs,1));
end
sObj.verify(m1);
sd2 = f(sObj,24);

Best Answer

Hello,
Fulden emailed me an example of how to get this to work, and I'm posting it here for reference. Thank you, Florian and Fuilden, for your help with this. This is my first time using the new scenarios object, and I'm really liking it now that I experienced its flexibility and how one can construct complex combinations with very few lines of code. It's a very nice addition to SimBiology! It would be good in the future if the 'sbiofit' command allowed the user to specify different scenarios for each of the groups.
clc
clear
m = sbmlimport('lotka');
cs = getconfigset(m);
set(cs.SolverOptions, 'RelativeTolerance', 1e-6);
% Define doses
d1 = sbiodose('dose for y1');
set(d1, 'TargetName', 'y1');
set(d1, 'Amount', 50);
d2 = sbiodose('dose for y2');
set(d2, 'TargetName', 'y2');
set(d2, 'Amount', 50);
% Define variants
v1 = sbiovariant('individual1');
v1.addcontent({'species', 'y1', 'value', 900});
v2 = sbiovariant('individual2');
v2.addcontent({'species', 'y1', 'value', 900});
v3 = sbiovariant('individual3');
v3.addcontent({'species', 'y1', 'value', 900});
% Create scenarios over variants and doses:
sObj = SimBiology.Scenarios('individuals', [v1, v2]);
add(sObj, 'cartesian', 'doses', [d1, d2]);
% Print content of scenarios object

disp(sObj)
% Create SimFunction and evaluate
f = createSimFunction(m, sObj, {'y1', 'y2'}, [], 'AutoAccelerate', false);
sd = f(sObj, 10);
sbioplot(sd);
% Add additional values to scenarios
sObj.updateEntry('individuals','Content', [v1, v2, v3]);
% Print content of scenarios object
disp(sObj)
sd = f(sObj, 10);
sbioplot(sd);