How to grab the first instance of a timestamp based on the second
2 ビュー (過去 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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1031695/image.png)
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!