how do obtain sum of two rows

6 views (last 30 days)
Johannes Deelstra
Johannes Deelstra on 14 Dec 2017
Edited: Johannes Deelstra on 15 Dec 2017
Have a 18482 x 7 matrix. I want to obtain a matrix which contains the sum of row 1 and 2, row 3 and 4, etc until the last ones being the sum of row 18481 and 18482. How do I do this. Thanks in advance

Answers (2)

Walter Roberson
Walter Roberson on 14 Dec 2017
output = YourMatrix(1:2:end, :) + YourMatrix(2:2:end, :);
  2 Comments
Rik
Rik on 14 Dec 2017
That's what you get with ambivalent questions, there are multiple answers that fit the question.
Johannes Deelstra
Johannes Deelstra on 15 Dec 2017
Edited: Johannes Deelstra on 15 Dec 2017
thanks for answering, two solutions, helpful

Sign in to comment.


Rik
Rik on 14 Dec 2017
x=rand(18482,7);
x2=sum(x,2);
x2=x2(1:2:end)+x2(2:2:end);

Categories

Find more on Introduction to Installation and Licensing 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!