See if datetime is within range
조회 수: 2 (최근 30일)
이전 댓글 표시
I have two datasets of datetime and numerical values where the data was collected at incongruous times. For example:
Dataset 1:
'3/25/2024 15:01:15' 1
'3/25/2024 15:01:31' 2
'3/25/2024 15:01:47' 0
'3/25/2024 15:02:03' 0
'3/25/2024 15:02:19' 0
'3/25/2024 15:02:35' 0
'3/25/2024 15:02:51' 1
'3/25/2024 15:03:07' 2
Dataset 2:
'3/25/2024 15:01:10' 10
'3/25/2024 15:01:26' 20
'3/25/2024 15:01:42' 30
'3/25/2024 15:01:58' 40
'3/25/2024 15:02:14' 50
'3/25/2024 15:02:30' 60
'3/25/2024 15:02:46' 70
I'd like to delete rows from dataset 1 and 2 that are in the same range of datetime. In this example, I'd like to delete the rows from dataset 1:
'3/25/2024 15:01:47' 0
'3/25/2024 15:02:03' 0
'3/25/2024 15:02:19' 0
'3/25/2024 15:02:35' 0
and therefore delete rows with the datetime in the same range from dataset 2:
'3/25/2024 15:01:58' 40
'3/25/2024 15:02:14' 50
'3/25/2024 15:02:30' 60
댓글 수: 2
Voss
2024년 3월 25일
You want to delete rows 3, 4, 5, and 6 from dataset 1, and also delete any rows from dataset 2 where the datetimes are within the range of the rows deleted from dataset 1. Is that right?
If so, why would rows 2 and 3 be deleted from dataset 2? Those are not in range (they are both before the first deleted dataset 1 datetime, '3/25/2024 15:01:47'). Only rows 4, 5, and 6 in dataset 2 are within the range '3/25/2024 15:01:47' to '3/25/2024 15:02:35'.
채택된 답변
Star Strider
2024년 3월 25일
I do not entirely understand what you want to do.
One approach —
D1 = {'3/25/2024 15:01:15' 1
'3/25/2024 15:01:31' 2
'3/25/2024 15:01:47' 0
'3/25/2024 15:02:03' 0
'3/25/2024 15:02:19' 0
'3/25/2024 15:02:35' 0
'3/25/2024 15:02:51' 1
'3/25/2024 15:03:07' 2};
D2 = {'3/25/2024 15:01:10' 10
'3/25/2024 15:01:26' 20
'3/25/2024 15:01:42' 30
'3/25/2024 15:01:58' 40
'3/25/2024 15:02:14' 50
'3/25/2024 15:02:30' 60
'3/25/2024 15:02:46' 70};
T1 = cell2table(D1);
T1.D11 = datetime(T1.D11)
T2 = cell2table(D2);
T2.D21 = datetime(T2.D21)
Lv = T1.D12 == 0;
T1Q = T1.D11(Lv);
T2Q = T2.D21 >= T1Q(1) & T2.D21 <= T1Q(end); % Logical Vector
T2deleted = T2(T2Q,:) % Deleted Rows
T2new = T2(~T2Q,:) % Retained Rows
.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!