Writing result of script (ran in a loop) into vector
1 view (last 30 days)
Show older comments
Hey,
I want to execute a script (main) in a loop which gives me a different result (solvertime) every time I run it and write this result into a vector with the size of the Number of runs.
NumOfRuns = 3;
results=zeros(1,NumOfRuns);
for i=1:NumOfRuns
main;
results(i)=solvertime;
end
For some reason it gives me this vector. Help is much appreciated.
4 Comments
Rik
on 12 Oct 2020
Regarding your flag ("I found out that the answer to this question was that "i" was somewhere in the script. so no one in this forum could know the answer. delete this please"):
We tend not to delete questions (especially those that have received valid attempts at an answer) unless there are very good reasons for doing so. Often the underlying reason is that the content should never have been made public in the first place. Because it is hard to say if something is usefull to some random passer-by in the future, we tend to want to keep content as-is. I don't see any such reason for deletion in your post, so I'm going to remove the flag. If you disagree, feel free to explain in a comment why you believe this question should be deleted. Just in case you were planning to delete the question content: I can easily restore it from this Wayback Machine capture, so you don't have to bother.
(Even though I do have some editorial priviliges through the reputation system, I am not afiliated with Mathworks and don't control anything on this website. Feel free to contact support if you want Mathworks to make a decision about this post.)
Answers (1)
Stephen23
on 9 Oct 2020
Something does not make much sense: given NumOfRuns = 3, why does results have 26 columns?
I suspect that the script also contains a variable named results, in which case there are two main solutions:
- rename one/both of those variables so that they have different names
- turn your script into a function (preferred approach).
2 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!