You are given an M x N matrix. Write a script that will compress this matrix into an M x (N/3) matrix, where each of the terms in the new matrix are the sum of three consecutive terms on each row. You can assume that N is evenly divisible by 3.
For example, if your original matrix is:
[1 7 13 19 25 31 2 8 14 20 26 32 3 9 15 21 27 33 4 10 16 22 28 34 5 11 17 23 29 35 6 12 18 24 30 36]
the output should be
[1+ 7+13 19+25+31 2+ 8+14 20+26+32 3+ 9+15 21+27+33 4+10+16 22+28+34 5+11+17 23+29+35 6+12+18 24+30+36]
or
[21 75
24 78
27 81
30 84
33 87
36 90]Good luck!
Solution Stats
Problem Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers98
Suggested Problems
-
Return the 3n+1 sequence for n
8486 Solvers
-
6436 Solvers
-
What is the distance from point P(x,y) to the line Ax + By + C = 0?
554 Solvers
-
Create a matrix X, where each column is a shifted copy of the vector v
221 Solvers
-
We love vectorized solutions. Problem 1 : remove the row average.
884 Solvers
More from this Author80
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!