Select data from timetable according to date and time
6 次查看(过去 30 天)
显示 更早的评论
Hello,
I want to plot some part of my data regarding smaller interval but I don't know how to create those interval since my time data is in datetime format.
I tried the isbetween function but I have this error message.
intervalStartTime = '12:37:48';
intervalEndTime = '12:37:58';
idx = isbetween (TTJosue.Time, intervalStartTime,intervalEndTime);
Error using datetime/isbetween>isbetweenUtil
All inputs must be datetime arrays or date/time character vectors or date/time strings.
Error in datetime/isbetween (line 59)
[aData,lData,uData] = isbetweenUtil(a,lowerLim,upperLim);
selectedRows = TTJosue(idx,:);
I don't understand where this error comes from because '12:37:48' and '12:37:58' are written in the same format as in my timetable, and I tried to formulate it differently.
Thanks,
Marine
回答(1 个)
Steven Lord
2022-8-2
If you want to determine if the time portion of a datetime falls in a certain window (regardless of the date portion) I recommend using the timeofday function to extract the time portion and calling isbetween on the resulting duration array and your time window data (also converted into duration arrays.)
First convert your time data into duration arrays.
intervalStartTime = '12:37:48';
intervalEndTime = '12:37:58';
dStart = duration(intervalStartTime)
dEnd = duration(intervalEndTime)
Now let's get a sample datetime and extract its time portion.
n = datetime('now')
dToCheck = timeofday(n)
dToCheck is not in the interval [dStart, dEnd] and so isbetween returns false.
isbetween(dToCheck, dStart, dEnd)
Let's create another datetime whose time portion is in that interval.
dt = datetime('today') + duration('12:37:53')
dToCheck2 = timeofday(dt)
Now isbetween will return true because of the day we built dt.
isbetween(dToCheck2, dStart, dEnd)
1 个评论
uzzi
2022-11-2
I am struggling with this question for quite a long time. Can you help me?
另请参阅
类别
在 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!