Run a script multiple times and save outputs

I have a script that at the end outputs a 1x5 array named 'g' with 5 values. each time i run the script, the values of 'g' will change. what can i use to run my script say, 50 times, and obtain a 50x5 array of all my different runs of 'g'?

 Respuesta aceptada

Stephan
Stephan el 19 de Oct. de 2019
Editada: Stephan el 19 de Oct. de 2019

0 votos

Write a function or a second script which calls your script in a for loop and save the results in a new line of a result matrix for every run of your loop.

3 comentarios

I initially tried this and i got it to work, but now im having trouble:
clc;clear;
gs=ones(5,5); %'gs' is where i will store each 1x5 'g'
for c = 1:5 %i would like to run 'problem3.m' 5 times and store each g in gs
run('problem3.m');
gs(c,:)=g;
end
Im getting the error:
Undefined function or variable 'c'.
Error in helploop (line 7)
gs(c,:)=g;
Tomás
Tomás el 19 de Oct. de 2019
Editada: Tomás el 19 de Oct. de 2019
My script (problem3.m) had
clc; clear;
at the beginning so removing that solved the issue.
Hi Tomas, I am trying to do the same you did but when I try to fill the matrix: (c:,) it says:
Unrecognized function or variable 'c'.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Productos

Versión

R2019a

Preguntada:

el 19 de Oct. de 2019

Comentada:

el 6 de Ag. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by