Resample multiple overlapping datetime to 1-minute (and 15-minutes) resolution?
2 次查看(过去 30 天)
显示 更早的评论
Coming back again on resampling datetime....
Situation is I have many water pumps which are filled up in different time-frames. I have this table with multiple overlapping time and the total volume of individual pumps. Each row is basically a different water pump.
Column 1 (Start time), Column 2 (End time), Column 3 (Volume)
I want to sample the data to minute resolution (also 15 mins resolution) with the specified volume.
Example:
Pump1: 00:04:34 06:33:34 56
Pump2: 00:10:09 09:50:01 93
What I want it
00:04:00 56
00:05:00 56
....
00:10:00 56+93
00:11:00 56+93
....
06:34:00 93
As you can see, it sums up when there is overlapping time. Or else it is the only volume.
I have attached the actual table as well.
Thanks!
7 个评论
Adam Danz
2019-8-21
编辑:Adam Danz
2019-8-21
I think I understand now. After you've interpolated the time stamps to minute resolution and replicated the volumne values, (as was demonstrated here), you get a timetable with two columns. Can you just apply the cumulative sum to the "vol" column? I haven't looked too closely as to why that wouldn't work.
[Update]
I think Steven's approach below is the way to go.
采纳的回答
Steven Lord
2019-8-21
Let's start off with two simple timetable arrays, one per pump.
pump1 = timetable(datetime(["01-Jan-2018 00:14:09"; "01-Jan-2018 11:22:13"]), ...
[2.87; 2.87], 'VariableNames', {'Volume_pump1'})
pump2 = timetable(datetime(["01-Jan-2018 00:16:40"; "01-Jan-2018 14:15:10"]), ...
[4.709; 4.709], 'VariableNames', {'Volume_pump2'})
synchronize the two timetable arrays to a new one whose Times are regularly spaced (every 15 minutes), spanning the union of the Times for the two smaller timetable arrays. I'm using linear interpolation and no extrapolation, so the pump is only 'on' during the range spanned by the Times in its smaller timetable array from above.
P = synchronize(pump1, pump2, 'regular', 'linear', ...
'TimeStep', minutes(15), ...
'EndValues', 0)
Note that because I told synchronize to give regular spacing and the Times from pump1 and pump2 aren't multiples of 15 minutes, they're not included. You could construct a NEWTIMES vector (combine the Times together and use bounds to determine the earliest and latest times) and pass that into synchronize if you need those exact times to be included.
To get the total volume:
P2 = timetable(P.Time, sum(P.Variables, 2), 'VariableNames', {'totalVolume'})
3 个评论
Steven Lord
2019-8-21
If you have multiple pump cycles, you'd probably want to add a row to each of the individual timetable arrays with Volume_pumpN equal to 0 at the start and end of each time the pump is turned off. Otherwise synchronize would think it's on continuously from the first time it turns on to the last time it turns off.
You could probably store all this data in one timetable with multiple variables from the start and use retime instead of synchronize but I don't have example code for that. It should be fairly similar.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Timetables 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!