Time interval of a continuous record

조회 수: 2 (최근 30일)
Queena Edwards
Queena Edwards 2022년 3월 31일
댓글: Siddharth Bhutiya 2022년 4월 1일
I would like to find the dureation between the following times. This is piece of a group of data called A.
NaN
22:00:00
23:00:00
00:00:00
01:00:00
NaN
16:00:00
17:00:00
NaN
06:00:00
NaN
14:00:00
15:00:00
16:00:00
NaN
The duration is one hour so it should display as:
NaN
01:00:00
01:00:00
01:00:00
01:00:00
NaN
01:00:00
01:00:00
NaN
01:00:00
NaN
01:00:00
01:00:00
01:00:00
NaN
  댓글 수: 3
Queena Edwards
Queena Edwards 2022년 3월 31일
yes it increases, as 00:00:00 is 00:00:00 "tomorrow" relative to 23:00:00 "today" . I have a column in my table showing the dates. The stuff I'm doing is a lil complex to explain so I chose to highlight what exactly i would like to focus on.
Siddharth Bhutiya
Siddharth Bhutiya 2022년 4월 1일
You mentioned that this is just an example, so in your original data, what is the data type of these values? Are these stored as durations or datetimes? If you are storing these as durations then as Steven mentioned above you are using durations to represents datetimes with some implicit assumptions. This will always mean you would have to do more work to get the right behavior. On the other hand if these were datetimes, then this becomes a simple call to diff
d
d =
15×1 datetime array
NaT
04-01-2022 22:00:00
04-01-2022 23:00:00
04-02-2022 00:00:00
04-02-2022 01:00:00
NaT
04-01-2022 16:00:00
04-01-2022 17:00:00
NaT
04-01-2022 06:00:00
NaT
04-01-2022 14:00:00
04-01-2022 15:00:00
04-01-2022 16:00:00
NaT
diff(d)
ans =
14×1 duration array
NaN
01:00:00
01:00:00
01:00:00
NaN
NaN
01:00:00
NaN
NaN
NaN
NaN
01:00:00
01:00:00
NaN

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by