Non-Overlapping Moving Sum
조회 수: 25 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
Star Strider
2021년 6월 27일
Try this —
Rain = [1,2,3,4,5,6,7,8,9,10];
rRain = reshape(Rain, 2, [])
sumRain = sum(rRain)
These could be combined into one line, however I kept them separate to demonstrate how it works.
.
댓글 수: 6
추가 답변 (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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!