Uneven time series averaging

2 ビュー (過去 30 日間)
Colin Edgar
Colin Edgar 2015 年 11 月 13 日
回答済み: Colin Edgar 2015 年 12 月 17 日
Need to get hourly averages of data which have uneven frequency over a given hour. Id is the 'sample' which is repeated over and over. Here is example data:
id hour data
1 17 376.2
2 17 376.1
3 17 375.9
4 17 375.7
5 17 375.9
1 17 375.7
2 18 375.9
3 18 376.1
4 18 376.3
5 18 376.6
1 18 377.0
2 18 377.2
3 19 377.5
4 19 377.7
5 19 378.0
1 19 378.1
2 19 378.4
3 19 378.6
4 19 378.7
5 20 378.8
I want to arrive at something this this in which the hours having 2 samples get a mean value:
hour id1 id2 id3 id4 id5
17 376.0 376.1 375.9 375.7 375.9
18 377.0 376.5 376.1 376.3 376.6
19 378.1 378.4 378.0 378.2 378.0
20 379.1 379.1 379.3 378.8 379.3
I have unique value index for HH and id having already used accumarray to collect the data as shown. Is there a way to use the 'aggregation function' of unstack() to do this?
newdata = unstack(data, {'data1'}, 'id');
I can't figure out the syntax based on mathworks help. Thanks....
  3 件のコメント
Colin Edgar
Colin Edgar 2015 年 11 月 13 日
dataout = unstack(datin, {'data'}, 'id', 'AggregationFunction', @mean);
Worked out the syntax for using unstack() in this way but doesn't solve my problem.
Colin Edgar
Colin Edgar 2015 年 11 月 14 日
I solved my problem using accumarray(). Will post code soon.

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

採用された回答

Colin Edgar
Colin Edgar 2015 年 12 月 17 日
I adapted this approach to work here. The key is correct use of unique() to get the index that identifies the groups you are working with.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by