See if datetime is within range
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Joy
el 25 de Mzo. de 2024
Comentada: Joy
el 25 de Mzo. de 2024
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 comentarios
Voss
el 25 de Mzo. de 2024
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'.
Respuesta aceptada
Star Strider
el 25 de Mzo. de 2024
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!