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

1 Ansicht (letzte 30 Tage)
clauper
clauper am 24 Jan. 2023
Bearbeitet: Stephen23 am 24 Jan. 2023
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 Kommentar
Stephen23
Stephen23 am 24 Jan. 2023
Bearbeitet: Stephen23 am 24 Jan. 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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Rik
Rik am 24 Jan. 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

Weitere Antworten (0)

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by