How to reduce a matrix size
110 ビュー (過去 30 日間)
古いコメントを表示
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!
0 件のコメント
採用された回答
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.
0 件のコメント
その他の回答 (1 件)
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]);
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!