フィルターのクリア

Compress down a 1000x1000 matrix into a 100x100 matrix

57 ビュー (過去 30 日間)
Ahmed Abdulla
Ahmed Abdulla 2020 年 6 月 7 日
コメント済み: larasupernovae 2022 年 3 月 3 日
I have a 1000x1000 matrix that contains various values. I would like to compress it down into a 100 by 100 matrix by averaging each 10 by 10 cell's values into 1, but im not really sure how to go about doing this

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 6 月 7 日
編集済み: Ameer Hamza 2020 年 6 月 7 日
If you have image processing toolbox
M = rand(1000, 1000);
M_new = blockproc(M, [10 10], @(x) mean(x.data, 'all'))
Alternative Solution 1: (surprisingly the fastest)
M_new = conv2(M, ones(10)/100, 'valid');
M_new = M_new(1:10:end, 1:10:end);
Alternative Solution 2:
M_C = mat2cell(M, 10*ones(1,100), 10*ones(1,100));
M_new = cellfun(@(x) mean(x, 'all'), M_C);
Alternative Solution 3:
M_new = zeros(size(M)/10);
for i=1:100
for j=1:100
M_new(i, j) = mean(M(10*(i-1)+1:10*i,10*(j-1)+1:10*j), 'all');
end
end
  2 件のコメント
Robert Jansen
Robert Jansen 2021 年 3 月 24 日
Amazing array of solutions. These all give the same results. The last one is surprisingly fast too. Thanks.
larasupernovae
larasupernovae 2022 年 3 月 3 日
thank you so much!

サインインしてコメントする。

その他の回答 (2 件)

David Hill
David Hill 2020 年 6 月 7 日
count=1;
for col=1:100:1000
for row=1:100:1000
newMatrix(count)=mean(yourMatrix(row:row+99,col:col+99),'all');
count=count+1;
end
end
newMatrix=reshape(newMatrix,10,[]);

Jan
Jan 2021 年 3 月 24 日
編集済み: Jan 2021 年 3 月 24 日
X = rand(1000, 1000);
Y = reshape(X, [10, 100, 10, 100]);
Z = reshape(sum(sum(Y, 1), 3), [100, 100]) / 100;
Or with FEX: BlockMean :
Z = BlockMean(X, 10, 10)

カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by