How to use a for loop to calculate the sum of a row vector?
Show older comments
I have the values x-[1, 23, 43, 72, 87, 56, 98, 33] How do you calculate the sum (which should equal 413) using a for loop?
Accepted Answer
More Answers (1)
Write a program (using loops) that calculates and displays the sum of all the elements of x=[2 -5 6 7; -4 8 -5 6];(its a question)
1 Comment
Yadu Bhusal
on 14 Aug 2021
X =['enter an array>']; m = length(x); Sum = 0; For i = 1:m Sum = sum + X(i); end Disp(sum)
IF you want single sum. It you wish iterations remove semicolon from end of X(i).
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!