フィルターのクリア

Resample/Match random interval data to interval timeseries

1 回表示 (過去 30 日間)
loes visser
loes visser 2017 年 3 月 9 日
回答済み: Peter Perkins 2017 年 3 月 9 日
Hi!
I have multiple arrays with data that that is collected randomly in time. Like;
a =
01-10-2016 00:00:00, 5
01-10-2016 00:00:03, 10
01-10-2016 00:00:08, 4
01-10-2016 00:00:10, 90
01-10-2016 00:00:11, 2
I would like to insert empty cells (NaN) between the measurements. Or match the data to a new timeserie, so I would get;
b =
01-10-2016 00:00:00, 5
01-10-2016 00:00:01, NaN
01-10-2016 00:00:02, NaN
01-10-2016 00:00:03, 10
01-10-2016 00:00:04, NaN
01-10-2016 00:00:05, NaN
01-10-2016 00:00:06, NaN
01-10-2016 00:00:07, NaN
01-10-2016 00:00:08, 4
01-10-2016 00:00:09, NaN
01-10-2016 00:00:10, 90
01-10-2016 00:00:11, 2
How can I accomplish this? interp or interp1 will fill every timestamp with a value, and this is not the goal.

回答 (1 件)

Peter Perkins
Peter Perkins 2017 年 3 月 9 日
If you have access to R2016b, use a timetable:
>> Time = {'01-10-2016 00:00:00'; '01-10-2016 00:00:03'; '01-10-2016 00:00:08'; '01-10-2016 00:00:10'; '01-10-2016 00:00:11'};
>> Time = datetime(Time,'InputFormat','MM-dd-yyyy HH:mm:ss');
>> x = [5; 10; 4; 90; 2];
>> tt = timetable(Time,x)
tt =
5×1 timetable
Time x
____________________ __
10-Jan-2016 00:00:00 5
10-Jan-2016 00:00:03 10
10-Jan-2016 00:00:08 4
10-Jan-2016 00:00:10 90
10-Jan-2016 00:00:11 2
>> tt = retime(tt,'secondly')
tt =
12×1 timetable
Time x
____________________ ___
10-Jan-2016 00:00:00 5
10-Jan-2016 00:00:01 NaN
10-Jan-2016 00:00:02 NaN
10-Jan-2016 00:00:03 10
10-Jan-2016 00:00:04 NaN
10-Jan-2016 00:00:05 NaN
10-Jan-2016 00:00:06 NaN
10-Jan-2016 00:00:07 NaN
10-Jan-2016 00:00:08 4
10-Jan-2016 00:00:09 NaN
10-Jan-2016 00:00:10 90
10-Jan-2016 00:00:11 2
Prior to 16b, it should be pretty easy to do that using a datetime in a table, and probably something like ismember, or perhaps interp1 on Time and x if you want to fill in those NaNs. Hope this helps.

カテゴリ

Help Center および File ExchangeTime Series についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by