How to take the mean of each four adjacent position in a matrix?

2 ビュー (過去 30 日間)
Ali Almakhmari
Ali Almakhmari 2022 年 6 月 12 日
回答済み: Chuguang Pan 2022 年 6 月 12 日
So I have this matrix variable that I attached here. Its 1536 by 2048, and I want to reduce it to 768 by 1024 by taking the mean of each four adjacent positions with the omitnan opition as well so I can take out the useless NaNs there. I hope someone can help. Thanks

採用された回答

Chuguang Pan
Chuguang Pan 2022 年 6 月 12 日
A=randi(10,1536,2048); % test Matrix
M=zeros(768,1024); % result Matrix
for row=1:768
for col=1:1024
M(row,col)=mean(A(2*row-1:2*row,2*col-1:2*col),'all','omitnan');
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by