how to determine if vector of row times is within timerange?

2 visualizzazioni (ultimi 30 giorni)
I have a vector of row times and a time range:
dates = datetime(2000,1,1):calyears(1):datetime(2002,1,1);
tr = timerange(datetime(2000,1,1), datetime(2001,12,31));
and I would like to determine whether "dates" is within the timerange, such that i get
answer = [true;true;false]
answer = 4×1 logical array
1 1 0 0
Is there a function or approach that does this?
  1 Commento
Stephen23
Stephen23 il 24 Gen 2023
Modificato: Stephen23 il 24 Gen 2023
Note that using datetime(2001,12,31) as the bin edge will miss any times that fall during the 31st of December:
isbetween(datetime(2001,12,31,12,35,45), datetime(2000,1,1), datetime(2001,12,31))
ans = logical
0

Accedi per commentare.

Risposta accettata

Rik
Rik il 24 Gen 2023
The timerange datatype is really only intended to be used with timetables. Once you convert your dates to a timetable, you can use the containsrange function:
dates = datetime(2000,1,1):calyears(1):datetime(2002,1,1);
tr = timerange(datetime(2000,1,1), datetime(2001,12,31));
tmp = timetable(reshape(dates,[],1),ones(numel(dates),1));
[tf,whichRows] = containsrange(tmp,tr)
tf = logical
1
whichRows = 3×1 logical array
1 1 0

Più risposte (0)

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Tag

Prodotti


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by