Saving the outputs of multiple runs of a script
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a stochastic simulation which I would like to run multiple times while changing a variable called 'correlation'.
For each run I would like to save the outputs as individual matrices so I can plot them together and compare values.
How would I go about saving the outputs of each simulation for each corresponding value of correlation?
I tried incorporating this into a 'for' statement but I'm very new to MATLAB and get the error "Array indices must be positive integers or logical values."
My code so far is:
R01= zeros(length(t),maxit);
R02= zeros(length(t),maxit);
R03= zeros(length(t),maxit);
R04= zeros(length(t),maxit);
R05= zeros(length(t),maxit);
R06= zeros(length(t),maxit);
R07= zeros(length(t),maxit);
R08= zeros(length(t),maxit);
R09= zeros(length(t),maxit);
for correlation=(0.1:0.1:0.9)
run stochasticsimulation.m
ResultsR01(:,correlation)= R01;
ResultsR02(:,correlation)= R02;
ResultsR03(:,correlation)= R03;
ResultsR04(:,correlation)= R04;
ResultsR05(:,correlation)= R05;
ResultsR06(:,correlation)= R06;
ResultsR07(:,correlation)= R07;
ResultsR08(:,correlation)= R08;
ResultsR09(:,correlation)= R09;
end
Could you please advise on either where to look to learn this stuff or what improvements I can make to my code.
Thanks!
0 commentaires
Réponse acceptée
VBBV
le 17 Mai 2021
%if
Count = 0.1:0.1:0.9;
for correlation=1:length(Count)
Change this line in for loop and run it.
2 commentaires
Plus de réponses (1)
Rik
le 17 Mai 2021
You should not be using a script outside of debugging. If you're only interested in the value of a single variable, you should make your script a function with that variable as the output. Then you can run it in a loop.
You should also note that indices in an array must be positive integers:
my_array(0.1) % this is an invalid syntax
my_array(1) % this is a valid syntax
You should also avoid numbering your variables, use indexing instead. If you only store a single value:
%change this
R01=my_function;
R02=my_function;
R03=my_function;
%to this:
R(1)=my_function;
R(2)=my_function;
R(3)=my_function;
0 commentaires
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!