search interval in datetime
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
hi, I have a datetime array of several many days. I need to serch interval
example:
TimeA=22:00
TimeB=03:00
search datetime>=timeA and datetime<=timeB (22:00 ..22:01..22:02. etc......23:59 ..00:00...00:01.etc... 2:58..2:59 3:00)
So I want without checking the day to have the indices of that range in the whole array
(the times in datetime are already ordered in a correct chronological way so the next time is always after the previous one)
0 Commenti
Risposta accettata
Steven Lord
il 21 Mag 2024
T = datetime('today') + hours(24*rand(10, 1))
TOD = timeofday(T)
Then compare to duration objects representing the ends of the interval of interest. In this case because the interval includes midnight we need to ask if the timeofday is greater than the first end or less than the second end.
past2200 = TOD > duration(22, 0, 0)
before0300 = TOD < duration(3, 0, 0)
T(past2200 | before0300)
results = table(T, past2200, before0300, past2200 | before0300, ...
'VariableNames', ["times", "> 2200", "< 0300", "overnight"])
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Calendar 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!