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!