How to reduce a matrix size in 1 dimension
6 views (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
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.
More Answers (0)
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!