Extracting index of specified date from datetime array in dd:MM:yyyy:HH:mm:ss.SSS format
15 ビュー (過去 30 日間)
古いコメントを表示
Hi All,
Getting frustrated as this should be seemingly simple to do. i have an array of datetime values in dd:MM:yyyy:HH:mm:ss.SSS format. I am trying to find the Index position of a specific time (03:04:2021:00:05:10.063)
TimeMatlab = [738249.003472956,738249.003530829,738249.003588699,738249.003646569,738249.003704439]
Time=datetime(TimeMatlab,'ConvertFrom','datenum','Format','dd:MM:yyyy:HH:mm:ss.SSS'); %Convert serial dates into dd:MM:yyyy:HH:mm:ss.SSS format
Time =
1×5 datetime array
03:04:2021:00:05:00.063 03:04:2021:00:05:05.063 03:04:2021:00:05:10.063 03:04:2021:00:05:15.063 03:04:2021:00:05:20.063
I then want to find the Index of 03:04:2021:00:05:10.063 in the datetime array Time (1,3).
The dates I need to serch for are in the dd:MM:yyyy:HH:mm:ss.SSS format hence I want to search for the index postion in Time rather than TimeMatlab if that makes sense.
Thanks
0 件のコメント
採用された回答
Chunru
2022 年 8 月 24 日
TimeMatlab = [738249.003472956,738249.003530829,738249.003588699,738249.003646569,738249.003704439];
Time=datetime(TimeMatlab,'ConvertFrom','datenum','Format','dd:MM:yyyy:HH:mm:ss.SSSSSSSS'); % SSSSSSS
T0=datetime("03:04:2021:00:05:10.063",'InputFormat','dd:MM:yyyy:HH:mm:ss.SSS')
Time-T0
[~, idx] = min(abs(seconds(Time-T0))) % closest one to T0
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!