Write a for loop that is equivalent to the command sum(A),whereA is a matrix.
Show older comments
Im having trouble understanding this question T4.5-4from the text i just need some help and steps on how to find the answers.
Answers (1)
Rafael Hernandez-Walls
on 14 Nov 2017
When you need to make a sum using a for cycle, it is necessary to initialize an accumulator variable to zero. This will allow you to perform your summation. The example I put below shows it. , it is added in columns.
A=magic(5);
SUM=zeros(1,5);
for k=1:5
for r=1:5
SUM(1,k)=SUM(1,k)+A(r,k);
end
end
SUM
2 Comments
James Tursa
on 14 Nov 2017
Please don't post complete answers to homework questions.
Rafael Hernandez-Walls
on 15 Nov 2017
Sorry!!!
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!