110 views (last 30 days)

Chandrasekhar
on 28 May 2014

sum(A')

Matt J
on 28 May 2014

Jos (10584)
on 28 May 2014

You do not want to store the results in separate variables R1, R2, etc., but rather as elements of a single variable R, with R(1), R(2), etc.

A = magic(3)

RowSum = sum(R,2)

help sum

Jos (10584)
on 28 May 2014

What do you mean, "not working"? Did you read the help of sum?

May be you want to sum along rows rows, i.e., sum the elements in each column?

ColumnSum = sum(R,1)

Next time, be a little bit more specific ...

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
## 1 Comment

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/131428-sum-of-the-elements-of-rows-of-matrix#comment_216366

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/131428-sum-of-the-elements-of-rows-of-matrix#comment_216366

Sign in to comment.