Resample/Match random interval data to interval timeseries
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Time Series 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!