MATLAB: How to reduce a matrix size in 1 dimension

matrixmatrix manipulationsize;

I would like to reduce the size of a matrix (M,N) in one direction (the rows) by averaging the values of neighboring cells.
So the cells (1,1), (1,2) in the old matrix will be represented by their average in (1,1) in the new matrix.
How can I do this?

Best Answer

Assuming that N is even:
reducedm = reshape(mean(reshape(m, M, 2, N/2), 2), M, N/2);
Note that I've averaged every two columns as per you example (:, 1) and (:, 2), which contradict the fact you said in the row direction. Just flip the matrix before and after and swap M for N, if you want rows.