How to grab the first instance of a timestamp based on the second

조회 수: 1 (최근 30일)
R
R 2022년 6월 14일
댓글: R 2022년 6월 14일
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!

채택된 답변

Peter Perkins
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 CenterFile Exchange에서 Data Preprocessing에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by