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

1 vue (au cours des 30 derniers jours)
R
R le 14 Juin 2022
Commenté : R le 14 Juin 2022
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!

Réponse acceptée

Peter Perkins
Peter Perkins le 14 Juin 2022
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

Plus de réponses (0)

Catégories

En savoir plus sur Data Preprocessing dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by