MATLAB: How to reinitialize the Species in the SimBiology Desktop to the final values of the last simulation in SimBiology 2.3 (R2008a)

simbioSimBiology

I am doing some steady state analysis of my SimBiology model and I would like to be able to automatically reinitialize my species to have the same amounts that they had at the end of the last simulation.
Is there a way to do this automatically with the GUI brought up using SBIODESKTOP?

Best Answer

The ability to reinitialize your species amounts from the results of a previous simulation is not directly available in the SimBiology Desktop in SimBiology 2.3 (R2008a).
As a workaround, you can export the model and the data object from the GUI to the workspace at the end of the simulation.
In the workspace, you can use the following code as a script. Please copy and paste this code into a MATLAB file and execute it after you have exported your model and data objects from your first simulation.
%%Reinitialize Species
% model object and data object must be exported as variables 'm' and
% 'sd' respectively
%%Get the states at the final time point
finaldata = sd.Data(end,:);
names = sd.DataNames;
%%Loop through the states (species) and set their initial Amounts
numSpecies = length(names);
for c = 1:numSpecies
speciesObj = sbioselect(m,'type','species','Name',names{c});
speciesObj.InitialAmount = finaldata(c);
end
%%Run the simulation again