filter function for aggregation of data

Hi everybody! I'm wondering if there is a way to solve the following problem in a more efficient way instead of a for cycle: I have a vector of hourly values and I would like to aggregate these values to 3 hour values with a moving window such that the first value would be the sum of the first three elements, the second value the sum of element 2,3 and 4, the third value the sum of element 3,4 and 5 and so on... I used a for loop but this takes me a lot of time. I knwo that this can be done with the filter function but I didn't understand how it works exactly. Does anybody know how to solve it? Thanks a lot Camilla

回答 (1 件)

Thorsten
Thorsten 2015 年 4 月 27 日

0 投票

x = randi(10, [1 10]); % sample data
F = 1/3*ones(1,3); % filter
xm3 = conv(x, F, 'valid');

4 件のコメント

Camilla Santicoli
Camilla Santicoli 2015 年 4 月 27 日
Thank you Thorsen but like this is makes the average, not the sum
Thorsten
Thorsten 2015 年 4 月 27 日
True. To get the sum, just use the filter
F = ones(1,3);
Camilla Santicoli
Camilla Santicoli 2015 年 4 月 27 日
thank you very much!
Thorsten
Thorsten 2015 年 4 月 27 日
Please accept the answer.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

質問済み:

2015 年 4 月 27 日

コメント済み:

2015 年 4 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by