matlab - Reduce matrix by adding every n -


not sure how explain here goes example:

a=[1 0 0 1 4 4 4 4    0 0 0 0 2 3 2 2    0 0 0 0 0 0 0 1    2 3 4 5 2 3 4 1 ] 

result:

b=[ 1 1 13 12     5 9 5  6]; 

each of elements computed adding n size submatrix inside original, in case n=2.

so b(1,1) a(1,1)+a(1,2)+a(2,1)+a(2,2), , b(1,4) a(1,7)+a(2,7)+a(1,8)+a(2,8).

visually , more clearly:

a=[|1 0| 0 1| 4 4| 4 4|    |0 0| 0 0| 2 3| 2 2|    ____________________    |0 0| 0 0| 0 0| 0 1|    |2 3| 4 5| 2 3| 4 1| ] 

b sum of elements on squares, in example of size 2.

i can imagine how make loops, feels vectorizable. ideas of how done?

assume matrix has sizes multipliers of n.

if have image processing toolbox blockproc option well:

b = blockproc(a,[2 2],@(x) sum(x.data(:))) 

Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -