Extracting index of specified date from datetime array in dd:MM:yyyy:HH:mm:ss.SSS format
15 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Chunru
il 24 Ago 2022
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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Dates and Time in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!