Calculate duration from labeled timestamped data.

4 ビュー (過去 30 日間)
Khandakar Rashid
Khandakar Rashid 2020 年 6 月 11 日
コメント済み: Khandakar Rashid 2020 年 6 月 20 日
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 Center および File ExchangeTimetables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by