Cut timetable data following certain conditions
Show older comments
I have created a timetable that has one minute timesteps. I would like to take this timetable and create most likely a cell object of chunks of the data following these conditions listed below. If there is a better way to get this data, I'd love to hear suggestions. Thanks!
Criteria:
-to keep data
- At least 5 min of continuous data (so positive, non-zero values)
- Maximum of 5 minutes of no non-zero values between times whne data is present.
-to break up data into chunks.
- No data for at least 60 minutes.
So, if there are five or more records with data, it should be taken and saved until the continuous records stop or, less than 6 values of no data between records occur. Then, after finding all these groups of data, I'd like to separate the groups with 60 minutes or more of no data between them.
Here's some sample data (timetable format):
'06-Feb-2019 03:40:00' 0 0
'06-Feb-2019 03:41:00' 0 0
'06-Feb-2019 03:42:00' 0 0
'06-Feb-2019 03:43:00' 0 0
'06-Feb-2019 03:44:00' 0 0
'06-Feb-2019 03:45:00' 0 0
'06-Feb-2019 03:46:00' 0 0
'06-Feb-2019 03:47:00' 0 0
'06-Feb-2019 03:48:00' 0 0
'06-Feb-2019 03:49:00' 0 0
'06-Feb-2019 03:50:00' 0.000900000000000000 0.00266666666666667
'06-Feb-2019 03:51:00' 0.00218333333333333 0.0195000000000000
'06-Feb-2019 03:52:00' 0 0
'06-Feb-2019 03:53:00' 0.00213333333333333 0.0118333333333333
'06-Feb-2019 03:54:00' 0.00286666666666667 0.0161666666666667
'06-Feb-2019 03:55:00' 0.00311666666666667 0.0213333333333333
'06-Feb-2019 03:56:00' 0.00161666666666667 0.00833333333333333
'06-Feb-2019 03:57:00' 0.00313333333333333 0.0173333333333333
'06-Feb-2019 03:58:00' 0.000633333333333333 0.00200000000000000
'06-Feb-2019 03:59:00' 0.00451666666666667 0.0521666666666667
'06-Feb-2019 04:00:00' 0 0
'06-Feb-2019 04:01:00' 0.000616666666666667 0.00183333333333333
'06-Feb-2019 04:02:00' 0 0
'06-Feb-2019 04:03:00' 0.000466666666666667 0.00133333333333333
'06-Feb-2019 04:04:00' 0.000500000000000000 0.00116666666666667
'06-Feb-2019 04:05:00' 0.00281666666666667 0.0141666666666667
'06-Feb-2019 04:06:00' 0.00376666666666667 0.0195000000000000
'06-Feb-2019 04:07:00' 0.00371666666666667 0.0150000000000000
'06-Feb-2019 04:08:00' 0.00235000000000000 0.00800000000000000
'06-Feb-2019 04:09:00' 0.00370000000000000 0.0151666666666667
'06-Feb-2019 04:10:00' 0.00341666666666667 0.0245000000000000
'06-Feb-2019 04:11:00' 0.00320000000000000 0.0170000000000000
'06-Feb-2019 04:12:00' 0.00410000000000000 0.0181666666666667
'06-Feb-2019 04:13:00' 0.00535000000000000 0.0396666666666667
'06-Feb-2019 04:14:00' 0.0116666666666667 0.0598333333333333
'06-Feb-2019 04:15:00' 0.00908333333333333 0.0375000000000000
'06-Feb-2019 04:16:00' 0.00708333333333333 0.0265000000000000
'06-Feb-2019 04:17:00' 0.00408333333333333 0.0126666666666667
'06-Feb-2019 04:18:00' 0.00598333333333333 0.0451666666666667
'06-Feb-2019 04:19:00' 0.0410166666666667 0.397333333333333
'06-Feb-2019 04:20:00' 0.0596166666666667 0.680333333333333
'06-Feb-2019 04:21:00' 0.0482500000000000 0.554166666666667
'06-Feb-2019 04:22:00' 0.0347333333333333 0.447500000000000
'06-Feb-2019 04:23:00' 0.00551666666666667 0.0335000000000000
'06-Feb-2019 04:24:00' 0.00425000000000000 0.0196666666666667
'06-Feb-2019 04:25:00' 0.00553333333333333 0.0450000000000000
'06-Feb-2019 04:26:00' 0.00823333333333333 0.0691666666666667
'06-Feb-2019 04:27:00' 0.00661666666666667 0.0560000000000000
'06-Feb-2019 04:28:00' 0.00968333333333333 0.0676666666666667
'06-Feb-2019 04:29:00' 0.00733333333333333 0.0455000000000000
'06-Feb-2019 04:30:00' 0.00471666666666667 0.0340000000000000
'06-Feb-2019 04:31:00' 0.00295000000000000 0.0191666666666667
'06-Feb-2019 04:32:00' 0.00441666666666667 0.0326666666666667
'06-Feb-2019 04:33:00' 0.00618333333333333 0.0575000000000000
'06-Feb-2019 04:34:00' 0.00696666666666667 0.0793333333333333
'06-Feb-2019 04:35:00' 0 0
'06-Feb-2019 04:36:00' 0 0
'06-Feb-2019 04:37:00' 0.000966666666666667 0.00616666666666667
'06-Feb-2019 04:38:00' 0 0
'06-Feb-2019 04:39:00' 0 0
'06-Feb-2019 04:40:00' 0 0
The data above should all be grouped together becasue breaks from 3:50 to 4:37 are less than 5 minutes. Let's assume that between the first timestep and ending timestep there were 60 consecutive zero values. I should metion that in all cases if one Variable is = 0 the second one will as well.
8 Comments
Adam Danz
on 3 Dec 2019
Unfortunately there's no easy way to copy-paste those values into a timetable that we can work with. Could you attach a mat file containing the timetable and any other related variables?
Off the bat I'll recommend not breaking the table apart. Instead, define a variable that merely indexes which rows should be selected and then whenever you need those rows, TT(rows,:) where TT is your timetable and rows is a logical index selecting rows to analyze.
Eric Escoto
on 3 Dec 2019
Eric Escoto
on 3 Dec 2019
"I tried to upload the file. Doesn't seem to want to attach. Any ideas on this?"
Were you trying to attach it using the paperclip icon? Was the file too large? If so, we really only need enough rows to cover the pattern you described.
"Can you expand on the alternative method?"
Whether you use that method or not, you'll need to create a variable that identifies the rows you want to select. My proposal is to use that variable to isolate the rows as you're working with the table rather than pulling the selected rows out of the table.
"Let's start with just indexing groups of data where a min of 5 minutes (records) are kept, with any rows of data adjacent (before or after) included if separated by 5 or less rows of no-data."
I think I understand this but an example would really make it solid. Could you provide a short example of a datetime vector (or whatever format your data are in) and which rows should be selected from that vector? Attaching the data would be even better but I'd still like to see an expected output for at least a section of the table.
Note that the data in your question all differ by 1 minute so we cannot see the pattern you're describing.
Eric Escoto
on 3 Dec 2019
Eric Escoto
on 6 Dec 2019
Edited: Eric Escoto
on 10 Dec 2019
Adam Danz
on 10 Dec 2019
No worries, good luck with finals!
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!