%% Select Simulation Data Using Names and Regular Expressions
% Load the model of glucose-insulin response. For details about the model, see the Background section in Simulating the Glucose-Insulin Response.

sbioloadproject('insulindemo.sbproj','m1');

%
% Suppress an information warning that is issued during simulations.

warnSettings = warning('off', 'SimBiology:DimAnalysisNotDone_MatlabFcn_Dimensionless');

%
% Simulate a single meal for a normal subject for 7 hours.

singleMeal = sbioselect(m1,'Name','Single Meal');
cs = getconfigset(m1,'active');
cs.StopTime = 7;
sd = sbiosimulate(m1,singleMeal)
sbioplot(sd);

%
% Select all species data logged in the SimData object sd.

[t,x,names] = select(sd,{'Type','species'});
names

%
% Plot data for the glucose rate of appearance and glucose utilization, namely Glu Appear Rate and Glu Util.

newsd = select(sd,{'Type','parameter','name',{'Glu Appear Rate'; 'Glu Util'}})
sbioplot(newsd);

%
% Compare data for the plasma glucose concentration (the species named Plasma Glu Conc) and insulin secretion rate (the parameter named Ins Secr). Use selectbyname to extract data by specifying the corresponding names.

newsd2 = selectbyname(sd,{'Plasma Glu Conc','Ins Secr'})
sbioplot(newsd2);

%
% Select data for all species and parameters that have Glu in their names.

newsd3 = select(sd,{'Where','Name','regexp','Glu'})
newsd3.DataNames

%
% You can also return the selected data as a structure.

sdStruct = select(sd,{'Where','Name','regexp','Glu'},'Format','struct');

%
% Restore the warning settings.

warning(warnSettings);

% Copyright 2019 The MathWorks, Inc.