run a program multiple times and save result

1 vue (au cours des 30 derniers jours)
Yaseen Teymouri
Yaseen Teymouri le 3 Fév 2021
Commenté : Yaseen Teymouri le 3 Fév 2021
Hi all
i want to run a genetic algorithm code multiple time(for example twice), and in each run save the result. can anyone help me???

Réponse acceptée

Bjorn Gustavsson
Bjorn Gustavsson le 3 Fév 2021
Modifié(e) : Bjorn Gustavsson le 3 Fév 2021
Sometimes I solve this problem this way:
if ~exist('run_idx.mat',2)
run_idx = 1;
save run_idx.mat;
else
load('run_idx.mat','run_idx')
run_idx = run_idx+1;
end % This gives you a run-index that you can increment in subsequent runs
%% Your other initializations
% Loop of genetic stuff
for i1 = 1:12, % Whatever you want
results = your_GA(input,arguments,etc);
savefilename = sprintf('your_GA_results-%02d.mat',run_idx)
save(savefilename,'results')
run_idx = run_idx+1;
save run_idx.mat;
end
This gives you a design where you incrementally count up the run-index so that all files saved get numbered, in addition by saving the incremented index you can continue in a following matlab-session and not overwrite the previous files.
HTH
  3 commentaires
Bjorn Gustavsson
Bjorn Gustavsson le 3 Fév 2021
My code snippet shows one way to run a function or process multiple times and then save the results in numbered files. That is what you asked for. I did not include any calls to genetic algorithms or the like. That part I assume you can insert in the appropriate place in the loop.
Yaseen Teymouri
Yaseen Teymouri le 3 Fév 2021
thanks

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by