필터 지우기
필터 지우기

Calculate duration from labeled timestamped data.

조회 수: 1 (최근 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 CenterFile Exchange에서 Timetables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by