- initialize a variable to the identity element for the operation you are using with respect to the field or group that you are calculating over
- loop over all elements of the array
- inside the loop, replace the variable with OPERATION applied between the variable and the loop value
- at the end of the loop, the variable holds the answer.
Sum of a Vector using a for loop
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Abraham Robledo
le 7 Fév 2019
Commenté : Adam Juckniewitz
le 6 Nov 2019
How can I find the sum of vector x=[3 5 12 42 67], using a simple for loop?
0 commentaires
Réponse acceptée
Walter Roberson
le 7 Fév 2019
Hint:
4 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!