Calculate duration from labeled timestamped data.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Khandakar Rashid
el 11 de Jun. de 2020
Comentada: Khandakar Rashid
el 20 de Jun. de 2020
Hi,
I have a timetable with timestamps and labels of different activities. The stacked plot looks like this.
I would like to calculate the durations of each cycle of the activity. For example, the top plot has 11 "Dump" sequences, so the outcome should be,
Dump = [t1, t2, ........t11], t = duration of each dump instance.
Is there any smarter way to accomplish this without using FOR loop and tracking changes in each row?
I am also attaching the .mat file of the timetable.
Thank you!
2 comentarios
Akira Agata
el 11 de Jun. de 2020
If possible, could you upload your timetable data so that people here can try their idea?
Respuesta aceptada
Akira Agata
el 18 de Jun. de 2020
Thank you for providing your data.
I believe the following is an possible solution. I hope this will be somehow helpful for you!
load('data.mat');
% Find start/end time for each 'Dump' period
idx = data.Truck1 == 'Dump';
locStart = find(diff(idx) == 1)+1;
locEnd = find(diff(idx) == -1);
timeStart = data.Time(locStart);
timeEnd = data.Time(locEnd);
% Calculate duration for each 'Dump' period
timeDuration = timeEnd - timeStart;
% Arrange to table
tblTruck1 = table(timeStart,timeEnd,timeDuration);
>> tblTruck1
tblTruck1 =
11×3 table
timeStart timeEnd timeDuration
_________ ________ ____________
06:44:46 06:45:44 00:00:58
06:56:53 06:57:48 00:00:55
07:11:13 07:12:21 00:01:08
07:27:06 07:28:15 00:01:09
07:38:22 07:39:19 00:00:57
07:52:06 07:53:02 00:00:56
08:01:43 08:02:30 00:00:47
08:12:52 08:13:39 00:00:47
08:28:23 08:29:19 00:00:56
08:40:42 08:41:35 00:00:53
08:54:25 08:55:23 00:00:58
Más respuestas (0)
Ver también
Categorías
Más información sobre Timetables 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!