How to do sliding window operation in Matlab?

5 Ansichten (letzte 30 Tage)
Ram k
Ram k am 18 Mai 2016
Kommentiert: Andrei Bobrov am 18 Mai 2016
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.

Antworten (2)

Duncan Po
Duncan Po am 18 Mai 2016
Bearbeitet: Duncan Po am 18 Mai 2016
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 am 18 Mai 2016
Bearbeitet: Andrei Bobrov am 18 Mai 2016
conv2(x,ones(1,10),'valid')
add
n = 10;
out = hankel(x(1:end-n+1),x(n+1:end));

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by