Resample/Match random interval data to interval timeseries

조회 수: 5 (최근 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 CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by