MATLAB Answers

0

How to use a for loop to calculate the sum of a row vector?

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?

  댓글 수: 0

로그인 to comment.

태그

답변 수: 2

Answer by Stalin Samuel on 25 Nov 2015
Edited by Stephen Cobeldick on 21 Dec 2018
 Accepted Answer

x = [1, 23, 43, 72, 87, 56, 98, 33] ;
y = 0;
for n = 1:length(x)
y = y + x(n);
end

  댓글 수: 4

표시 이전 댓글 수: 1
Better to use a variable with a name other than 'sum', since that is the name of an existing MATLAB function.
Needed this, thanks for the post!
what is the use of x(n).

로그인 to comment.


Answer by Aza Xongo on 16 Apr 2019
Edited by Aza Xongo on 16 Apr 2019

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)

  댓글 수: 0

로그인 to comment.



Translated by