Commit d1cfd128 by Chiara Antonini

Upload new file

1 parent 894cb883
%Function executed when the button START SIMULATION in the main GUI is
%pushed. It takes in input the handles of the main GUI.
function start_simulation(handles,hObject)
%tic
%cell array where the measured variables for all independent realizations
%are saved
AllResults=cell(handles.Nr,length(handles.Model.Species));
AllPerturbations=cell(handles.Nr,1);
%retrieve parameters and observables of the model
handles.num_param=length(handles.Model.Parameters);
handles.param_name=get(handles.Model.Parameters,'Name');
handles.nominal_p=cell2mat(get(handles.Model.Parameters,'value'))';
obs_name=get(handles.Model.Species,'Name');
handles.time_results=[0:handles.step_size:handles.csObj.StopTime]';
set(handles.text14,'string','');
h = waitbar(0,'Please wait...');
%for each independent realization k
for k=1:handles.Nr
waitbar(k/handles.Nr,h,['Realization number ',num2str(k)]);
%Latin Hypercube generation for perturbing the parameter space
hypercube=LatinHypercube(handles.LBpi,handles.UBpi,handles.Nsample);
handles.perturbation=hypercube.generate_sample(handles.num_param);
perturbed_p=repmat(handles.nominal_p,length(handles.perturbation),1).*handles.perturbation;
AllPerturbations{k,1}=handles.perturbation;
disp(strcat('Generated a Latin Hypercube of size',{' '},sprintf('%.0f',size(handles.perturbation,1)),'x',sprintf('%.0f',size(handles.perturbation,2))));
%creation of a SimFunction object for performing model simulations
modelsim=createSimFunction(handles.Model, handles.param_name, obs_name,[],'UseParallel',true);
[tsim_all,psim_all]=modelsim(perturbed_p,[],[],handles.time_results);
%ArrayResults is a cell array for saving measured variables of each
%single realization. Then, these results are all saved in the cell
%array AllResults
ArrayResults=cell(handles.Nsample, length(handles.Model.Species));
for i=1:handles.Nsample
for j=1:length(handles.Model.Species)
ArrayResults{i,j}=psim_all{i,1}(:,j);
end
end
for j=1:length(handles.Model.Species)
AllResults{k,j}=ArrayResults(:,j);
end
disp(strcat('Completed one realization. The array of results has size',{' '},sprintf('%.0f',size(psim_all,1)),'x',sprintf('%.0f',size(psim_all,2))));
end
handles.AllResults=AllResults;
handles.AllPerturbations=AllPerturbations;
delete(gcp)
%save(fullfile(handles.folder,'measuresPeng2016.mat'),'-v7.3');
close (h) %close the waitbar
%handles.elapsedtime=toc;
%set(handles.text14,'string',strcat('All done!Time employed for model simulation is',handles.elapsedtime));
%drawnow;
guidata(hObject,handles);
end
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!