How to do sliding window operation in Matlab?

3 visualizaciones (últimos 30 días)
Ram k
Ram k el 18 de Mayo de 2016
Comentada: Andrei Bobrov el 18 de Mayo de 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.

Respuestas (2)

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

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by