フィルターのクリア

How to do sliding window operation in Matlab?

1 回表示 (過去 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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by