How to do sliding window operation in Matlab?

조회 수: 3 (최근 30일)
Ram k
Ram k 2016년 5월 18일
댓글: Andrei Bobrov 2016년 5월 18일
Suppose I Have a sequence
x=[4,1,1,1,2,2,3,5,9,7,7,7,6,6,1,1,2,3,4,4],
and I want addition for sliding window of size 10, i.e. addition of sequence
[4,1,1,1,2,2,3,5,9,7]
i.e. 4+1+1+1+2+2+3+5+9+7=35,then skipping 1st and adding next element of sequence i.e. addition for
[1,1,1,2,2,3,5,9,7,7],
then next i.e. addition for
[1,1,2,2,3,5,9,7,7,7]
likewise upto last window i.e.
[7,7,6,6,1,1,2,3,4,4],
how to do it.

답변 (2개)

Duncan Po
Duncan Po 2016년 5월 18일
편집: Duncan Po 2016년 5월 18일
R2016a has a new function movsum:
>> x=[4,1,1,1,2,2,3,5,9,7,7,7,6,6,1,1,2,3,4,4]
>> movsum(x,10,'EndPoints','discard')
ans =
35 38 44 49 54 53 52 51 49 44 41
Loren's blog has an article on these new additions: http://blogs.mathworks.com/loren/2016/04/15/moving-along/

Andrei Bobrov
Andrei Bobrov 2016년 5월 18일
편집: Andrei Bobrov 2016년 5월 18일
conv2(x,ones(1,10),'valid')
add
n = 10;
out = hankel(x(1:end-n+1),x(n+1:end));

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by