MATLAB Answers

How can I sum the elements in a vector row without using the sum function or any form of loops?

10 views (last 30 days)
Keaton Winder
Keaton Winder on 26 Mar 2020
Commented: Stephen Cobeldick on 26 Mar 2020
How can I sum the elements in a vector row without using the sum function or any form of loops?

  0 Comments

Sign in to comment.

Answers (2)


Peng Li
Peng Li on 26 Mar 2020
I don't quite understand your point about not using the function sum. But it is definitely possible to not use any form of loop.
suppose A is a matrix. sum(A) or sum(A, 1) calculates the sum along the first dimension (row). It gives the sum of each column, thus resulting you a row vector.
sum(A, 2) calculates the sum along the second dimension (column), thus throwing you a column vector with each element the sum of each row.

  0 Comments

Sign in to comment.

Tags

Products


Release

R2019b