Calculate duration from labeled timestamped data.

2 次查看(过去 30 天)
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 个评论
Akira Agata
Akira Agata 2020-6-11
If possible, could you upload your timetable data so that people here can try their idea?
Khandakar Rashid
Khandakar Rashid 2020-6-11
Thank you Akira. I have uploaded the timetable data in the original question as "data.mat".

请先登录,再进行评论。

采纳的回答

Akira Agata
Akira Agata 2020-6-18
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
  1 个评论
Khandakar Rashid
Khandakar Rashid 2020-6-20
Thank you so much Akira. Although I figured out a way to do this, your solution is much more elegant. I am going to use it :D :D

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Timetables 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by