Save multiple run result of script

Hi i'm writing a code with matlab, i wonder if there is a way to save the result of my script every time i run it.Example if i run this code multiple times i want to get all different outputs in my vector or file in case of using save function.
s=[];
s=fitness(D,vect);
Because every time i execute, it overwrites the last result.
Thank you.

 Respuesta aceptada

KL
KL el 20 de Nov. de 2017
Editada: KL el 20 de Nov. de 2017
EDITED
numOfRuns = 5;
for n=1:numOfRuns
s = fitness(D,vect);
save(['result_data_run_number_' num2str(n) ',mat'],'s');
end

5 comentarios

yh sf
yh sf el 20 de Nov. de 2017
I tried it but i get the error 'Argument must contain a string.' in save because of 's'
KL
KL el 20 de Nov. de 2017
Sorry, my bad. It should have been
save(['result_data_run_number_' num2str(n) ',mat'],'s');
yh sf
yh sf el 20 de Nov. de 2017
I fixed it but then i still have the same problem because the loop executes in one run and i get same results
KL
KL el 20 de Nov. de 2017
You will get different results only if you change some of your code. I only showed you how to run a code multiple times and store the outcome in different mat files.
Put the part of the code you want to repeat inside for loop and save should be at the end of the loop.
yh sf
yh sf el 20 de Nov. de 2017
Thank you, my fault, so obvious but i was stuck with the idea that i have to click on the run button every time.

Iniciar sesión para comentar.

Más respuestas (1)

Stephen23
Stephen23 el 20 de Nov. de 2017
Editada: Stephen23 el 4 de Nov. de 2024
An alternative to using a loop: download my FEX submission nextname, which will generate the next filename each time you call it. Simply put this in your script to generate the filename:
name = nextname('result_<1>.mat')

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

el 20 de Nov. de 2017

Editada:

el 4 de Nov. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by