# Non-Overlapping Moving Sum

13 ビュー (過去 30 日間)
Suman Dhamala 2021 年 6 月 27 日
コメント済み: Suman Dhamala 2021 年 6 月 27 日
Consider any matrix, say Rain=(1:10)'. I want to compute a non-overlapping moving sum with two element.
Rain=1,2,3,4,5,6,7,8,9,10
Compute=1+2,3+4,5+6,7+8,9+10
With traditional movsum command, the moving sum is overlapping elements. I want to evaluate non-overlapping moving sum. Any in-built function? I have tried with loops and all those, it works but in-built function would be fast to compute.

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

### 採用された回答

Star Strider 2021 年 6 月 27 日
Try this —
Rain = [1,2,3,4,5,6,7,8,9,10];
rRain = reshape(Rain, 2, [])
rRain = 2×5
1 3 5 7 9 2 4 6 8 10
sumRain = sum(rRain)
sumRain = 1×5
3 7 11 15 19
These could be combined into one line, however I kept them separate to demonstrate how it works.
.
##### 6 件のコメント4 件の古いコメントを表示4 件の古いコメントを非表示
Star Strider 2021 年 6 月 27 日
@Matt J — Thank you! I didn’t think to look in FEX.
Suman Dhamala 2021 年 6 月 27 日
This worked thanks @Matt J and everyone

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

### その他の回答 (1 件)

Image Analyst 2021 年 6 月 27 日
Since you have an image, you can do it with blockproc. However it only works with 2-D arrays so you'll have to do it once on each slice, then again along the z direction. I'm attaching some blockproc demos. I haven't done it with a 3-D image so you're on your own but I'm pretty sure it can be done.

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

### カテゴリ

Help Center および File ExchangeImages についてさらに検索

R2019a

### Community Treasure Hunt

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

Start Hunting!

Translated by