How to sum n lines of a matrix to another matrix?
Show older comments
So basically, i have a matrix Apit with the index of (51*n,5,1000) and what i wanted is another matrix TotalApit, with the index (51,5,1000), that sums up 'n' lines by 'n' lines.
like:
if n = 2, Apit(102,5,1000) and TotalApit(51,5,1000)
TotalApit(1,1,1) = Apit(1,1,1)+Apit(2,1,1)
TotalApit(2,1,1) = Apit(3,1,1)+Apit(4,1,1)
So i want that 1 line of TotalApit correspond the sum of n lines of Apit
Can someone help me?
2 Comments
Image Analyst
on 23 Sep 2018
Explain how the first indexes (row number) are determined on the right hand side. Like why row is 1 and 2 in the first equation, and 3 and 3 (the same) in the second equation. What rule are you using to determine which rows to sum?
And, this is not a big array, just a simple for loop would work, though there are more efficient ways.
Pedro Vicente
on 23 Sep 2018
Accepted Answer
More Answers (1)
Kaushik Lakshminarasimhan
on 23 Sep 2018
n=2;
TotalApit = reshape(sum(reshape(Apit,[n 102/n 5 1000])),[102/n 5 1000]);
Categories
Find more on Matrices and Arrays 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!