Datetimes don't seem to be recognised

조회 수: 2 (최근 30일)
Louise Wilson
Louise Wilson 2021년 11월 10일
댓글: Steven Lord 2021년 11월 10일
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