Datetimes don't seem to be recognised

3 次查看(过去 30 天)
Can anyone explain to me why this isn't working? For some reason, the datetime t is not recognised as occurring between times.t1.start and times.t1.end, even though it DOES! It is recognised as occurring after t1.start, but not before t1.end.
isbetween() also does not work so I am guessing I have overlooked something simple...
start=datetime(2021,08,11,09,58,25);
last=datetime(2021,08,11,10,01,00);
t=gps.DateTime(ii) %reading same datetime from my table
t=datetime(2021,08,11,09,59,25)
%if vessel position time occurs during particular transect working on
if (t>=start)&&(t<last)
%append it to specific part of structure
disp('It works!')
else
disp('It does not work')
end
%Datetime from my table:
t =
datetime
11-Aug-2021 09:59:25
%Datetime datetime(2021,08,11,09,59,25)
t =
datetime
11-Aug-2021 09:59:25

采纳的回答

Star Strider
Star Strider 2021-11-10
I’m not certain what you’re doing and I can’t run the posted code. I’m also not certain what the actual problem is.
See if the isbetween function will do what you want with respect to the if block.
.
  20 个评论
Louise Wilson
Louise Wilson 2021-11-10
All good, it works perfectly :-) Thank you. The data I am working with is huge and a lot of time consuming processing has already been done so the fix up solution is preferrable by far!
Steven Lord
Steven Lord 2021-11-10
If that doesn't work, perhaps the data in the file was more precise than you thought it was.
t1 = datetime(2021, 11, 10, 14, 25, 00)
t1 = datetime
10-Nov-2021 14:25:00
t2 = datetime(2021, 11, 10, 14, 25, 0.4)
t2 = datetime
10-Nov-2021 14:25:00
t1 >= t2 % correctly false even though they display the same
ans = logical
0

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by