How to reduce a matrix size

조회 수: 109 (최근 30일)
Oluwa KuIse
Oluwa KuIse 2012년 3월 12일
댓글: Martin Grden 2021년 6월 1일
I want to reduce the size of a matrix (M,N) by a fourth by averaging the values of neighboring cells.
So for instance the cells (1,1), (1,2), (2,1) and (2,2) in the old matrix will now be represented by their average which will be stored in (1,1) of the new matrix.
How can I code this?
Thanks!

채택된 답변

Jan
Jan 2012년 3월 12일
X = rand(20, 30);
R = reshape(X, 2, 10, 2, 15);
S = sum(sum(R, 1), 3) * 0.25;
Y = reshape(S, 10, 15);
This can be wriiten in one line also. If more speed is needed you can use the faster C-Mex FEX: BlockMean.

추가 답변 (1개)

Christian Zitzmann
Christian Zitzmann 2020년 6월 9일
The question is very old and propably already solved, but I've got a very nice solution as well.
X = reshape(1:400,20,20);
Y = imresize(X,[3,3]);
  댓글 수: 1
Martin Grden
Martin Grden 2021년 6월 1일
Nice, it helped me.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by