Lets say I have a time T1 = '2018-03-14 16:30:54' and another T2 = '2018-03-14 16:40:54' How can I find the total duration of the interval, as well as a "midpoint" in between said interval? My goal is to add an NaN entry every time there is a time gap greater than 10 minutes.
For example; '2018-03-14 16:30:54' '2018-03-14 16:40:54' %NaN entry would be added here '2018-03-14 17:20:15' '2018-03-14 17:30:15'
The purpose of adding this entry would be to remove discontinuity in graphs.

 채택된 답변

the cyclist
the cyclist 2018년 4월 18일
편집: the cyclist 2018년 4월 18일

1 개 추천

T1 = datetime('2018-03-14 16:30:54');
T2 = datetime('2018-03-14 16:40:54');
dT = T2 - T1;
T_mid = T1 + dT/2;

댓글 수: 3

Miguel Herrera
Miguel Herrera 2018년 4월 18일
Thank you. Follow up question, what can I do to make the following code work if dT > 00:12:00 disp('TRUE') else disp('FALSE') end
I keep getting TRUE even though the answer should be false. Does this have to do with the fact that dT is a duration and should also be compared to another duration using that if statement?
the cyclist
the cyclist 2018년 4월 19일
편집: the cyclist 2018년 4월 19일
There might be a better way, but ...
dT > duration('12:00','InputFormat','mm:ss')
dT > hours(12)
The cyclists code will work in R2018a or later, but in any case using hours seems much more readable to me.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Peter Perkins
Peter Perkins 2018년 4월 19일

1 개 추천

>> d = datetime(2018,3,14,16,[30 40],54)
d = 
  1×2 datetime array
   14-Mar-2018 16:30:54   14-Mar-2018 16:40:54
>> mean(d)
ans = 
  datetime
   14-Mar-2018 16:35:54
>> diff(d)
ans = 
  duration
   00:10:00
Steven Brossi
Steven Brossi 2022년 8월 8일

0 개 추천

How about
T1 = datetime('2018-03-14 16:30:54')
T1 = datetime
14-Mar-2018 16:30:54
T2 = datetime('2018-03-14 16:40:54')
T2 = datetime
14-Mar-2018 16:40:54
T_mid = mean([T1, T2])
T_mid = datetime
14-Mar-2018 16:35:54

카테고리

도움말 센터File Exchange에서 Dates and Time에 대해 자세히 알아보기

질문:

2018년 4월 18일

답변:

2022년 8월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by