How to reduce a matrix size in 1 dimension

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?

 Accepted Answer

Guillaume
Guillaume on 10 Oct 2014
Edited: Guillaume on 10 Oct 2014
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.

1 Comment

Great!! Thank you very much! Best regards, Henrik

Sign in to comment.

More Answers (0)

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Asked:

on 10 Oct 2014

Commented:

on 10 Oct 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!