- 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 次查看(过去 30 天)
显示 更早的评论
How can I find the sum of vector x=[3 5 12 42 67], using a simple for loop?
0 个评论
采纳的回答
Walter Roberson
2019-2-7
Hint:
4 个评论
更多回答(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!