MATLAB: To change 12×12 matrix to 6X12

loopMATLABmatricesmatrix

How can i add a loop to add the 1st two rows of a matrix and then 3rd and 4th row of a matrix and so on till the addition of 11th and 12th row so as to get a 6×12 matrix instead of 12×12 matrix.
for example:
r= 1 2 3 4
5 6 7 8
9 0 1 2
3 4 5 6]
that is 4×4 matrix.
answer= 6 8 10 12
12 4 6 8
converted to 2×4 matrix.
so similar manner how to convert 12×12 matrix to 6×12 matrix using any loop or normal command.

Best Answer

Answer = reshape(r(1:2:end)+r(2:2:end),[],size(r,2))