Summing the values inside a while loop
3 次查看(过去 30 天)
显示 更早的评论
I was wondering how we can sum up the values we get inside a while loop outside of the while loop so for example in a while loop you are getting different scores and by the end of the loop, you want to sum all those scores you get. I used the sum function but it just prints out the last score not all of them!
0 个评论
回答(1 个)
Voss
2023-3-10
scores = [];
ii = 1;
while ii <= 10
scores(end+1) = rand();
ii = ii+1;
end
scores
sum(scores)
0 个评论
另请参阅
类别
在 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!