Writing result of script (ran in a loop) into vector
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Rik
2020-10-12
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.)
回答(1 个)
Stephen23
2020-10-9
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!