Summing the values inside a while loop
조회 수: 15 (최근 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!