How to consolidate a vector of time stamps and perform interpolation to calculate the missing items?
1 次查看(过去 30 天)
显示 更早的评论
I have several matrices containing recording of a physical quantity and a timestamp of when the recording was taken (technically at a fixed frequency). The problem is that even though the observation time is the same for all the different sensors, the total number of elements in each matrix is different. Since we are talking about hundreds of thousands of recordings, I can only guess some recordings are not there and therefore I end up with fewer elements than I should. I would like to scan the times, detect if any is missing and in that case perform interpolation in-between the two closest values to fill the gap. The first problem I am encountering is converting the time stamps into a format that is easily manipulated in Matlab. The format I have in the database is MM/DD/YYYY HH:MM:SS AM. Matlab will not recognize this as a date and time and therefore I am not able to perform any operations on the vector. The second problem would be to find the missing items and perform oversampling based on the values I have. The easiest way would be to simply interpolate between the prior and subsequent value found in the time stamp. My date vector would look something like this:
A = ['01/01/2017 00:00:00 AM'; '01/01/2017 00:15:00 AM'; '01/01/2017 00:30:00 AM'; '01/01/2017 01:00:00 AM'];
and obviously the missing item would be 00:45:00AM on 01/01/2017.
0 个评论
采纳的回答
jonas
2018-8-14
Your first problem is a non-issue. Just read your times like this
A = datetime(A,'format','MM/dd/yyyy hh:mm:ss aa')
A =
4×1 datetime array
01/01/2017 12:00:00 AM
01/01/2017 12:15:00 AM
01/01/2017 12:30:00 AM
01/01/2017 01:00:00 AM
Put these times, together with your data, into a timetable, TT. For each sensor, you will then have a timetable.
Now, onto the interpolation part. I would suggest that you build a complete time-vector and use retime with your entire dataset. You can then use synchronize to obtain the exact same sampling times on all your sensors and concatenate your data into one single timetable. The first step is to build a complete time-vector:
t_new=datetime('01/01/2017 00:00:00 AM','format','MM/dd/yyyy hh:mm:ss aa'):minutes(15):datetime('01/01/2017 01:00:00 AM','format','MM/dd/yyyy hh:mm:ss aa')
Then just retime
out=retime(TT,t_new);
then synchronize
TT_new = synchronize(TT1,TT2)
This should give you an idea of how to proceed. If you want help with the details, please upload some sample data.
2 个评论
jonas
2018-8-15
编辑:jonas
2018-8-15
Happy to help! Yes both timetable and readtable are great! readtable also has a ton of import options (see detectimportoptions ) for when it fails to import automatically
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Timetables 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!