- 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
1 view (last 30 days)
Show older comments
Abraham Robledo
on 7 Feb 2019
Commented: Adam Juckniewitz
on 6 Nov 2019
How can I find the sum of vector x=[3 5 12 42 67], using a simple for loop?
0 Comments
Accepted Answer
Walter Roberson
on 7 Feb 2019
Hint:
4 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!