How to grab the first instance of a timestamp based on the second
1 次查看(过去 30 天)
显示 更早的评论
Hello everyone.
I was having some trouble figuring out how I could filter out rows of data when we have a high frequency data sample.
Ex:
As you can see in the image, this is a tall table and it consists of multiple timestamps but with varying milliseconds. I want to be able to grab the first instance of the rows where the timestamp based on the seconds is unique. So 14-06-2022-15:30:19.6175... then 14-06-2022-15:30:20.042563... then 14-06-2022-15:30:21.00559
Thank you for your help!
0 个评论
采纳的回答
Peter Perkins
2022-6-14
It's a one-liner using a timetable and retime, with NewTimeStep 'secondly' and Method 'firstValue':
>> tt = timetable(rand(10,1),RowTimes=datetime("now",Format="dd-MMM-uuuu HH:mm:ss.SSS")+seconds(3*sort(rand(10,1))))
tt =
10×1 timetable
Time Var1
________________________ _______
14-Jun-2022 09:21:07.985 0.79595
14-Jun-2022 09:21:08.243 0.23337
14-Jun-2022 09:21:08.543 0.60084
14-Jun-2022 09:21:08.585 0.11246
14-Jun-2022 09:21:08.840 0.51577
14-Jun-2022 09:21:08.913 0.83784
14-Jun-2022 09:21:09.180 0.92079
14-Jun-2022 09:21:09.732 0.49823
14-Jun-2022 09:21:10.403 0.27761
14-Jun-2022 09:21:10.574 0.65252
>> tt2 = retime(tt,"secondly","firstvalue")
tt2 =
4×1 timetable
Time Var1
________________________ _______
14-Jun-2022 09:21:07.000 0.79595
14-Jun-2022 09:21:08.000 0.23337
14-Jun-2022 09:21:09.000 0.92079
14-Jun-2022 09:21:10.000 0.27761
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Preprocessing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!