Summing the values inside a while loop
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Voss
el 10 de Mzo. de 2023
scores = [];
ii = 1;
while ii <= 10
scores(end+1) = rand();
ii = ii+1;
end
scores
sum(scores)
0 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!