Resample/Match random interval data to interval timeseries
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Peter Perkins
am 9 Mär. 2017
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 Kommentare
Siehe auch
Kategorien
Mehr zu Time Series finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!