Matrix moving mean with overflow average

1 回表示 (過去 30 日間)
Albert Zurita
Albert Zurita 2022 年 11 月 13 日
コメント済み: Albert Zurita 2022 年 11 月 15 日
I am wondering if there is a (simply) way when using movmean for controlling row overflow and for specifying a rectangular window instead of a square window. The idea would be to keep averaging the patch corresponding to each number in red until the end of row is found, and simply jump to the next row. Thanks!

採用された回答

Matt J
Matt J 2022 年 11 月 13 日
編集済み: Matt J 2022 年 11 月 13 日
Here's one way. I assumed here you want the same wrap-around to occur in the lower-right corner of the matrix as well.
A=reshape(1:24,[],4)'
A = 4×6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
B=[A,circshift(A(:,1:2),-1) ]
B = 4×8
1 2 3 4 5 6 7 8 7 8 9 10 11 12 13 14 13 14 15 16 17 18 19 20 19 20 21 22 23 24 1 2
slidingMeans=conv2(B,ones(3)/9,'valid')
slidingMeans = 2×6
8.0000 9.0000 10.0000 11.0000 12.0000 13.0000 14.0000 15.0000 16.0000 17.0000 15.3333 13.6667
  5 件のコメント
Matt J
Matt J 2022 年 11 月 15 日
win = [3 5]; % rows, cols
A=reshape(1:24,[],4)'
A = 4×6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
B=[A,circshift(A(:,1:win(2)-1),-1)];
B(end,end-win(2)+2:end)=nan
B = 4×10
1 2 3 4 5 6 7 8 9 10 7 8 9 10 11 12 13 14 15 16 13 14 15 16 17 18 19 20 21 22 19 20 21 22 23 24 NaN NaN NaN NaN
slidingMeans=conv2(B,ones(win)/prod(win),'valid' )
slidingMeans = 2×6
9.0000 10.0000 11.0000 12.0000 13.0000 14.0000 15.0000 16.0000 NaN NaN NaN NaN
Albert Zurita
Albert Zurita 2022 年 11 月 15 日
This is excellent, and good methodology I learnt, thanks!

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

その他の回答 (0 件)

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by