Sum of rows based on time range
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
What I am trying to do is sum rows for every 10 days consecutive days. The problem that I have is in my dataframe, is that I have so many missed days, and by applying a function that will sum every 10 rows, it will not be practical as it can sum non-consecutive days. So I am looking for a solution to sum only every 10 consecutive days.
Regards,
0 Kommentare
Antworten (1)
Star Strider
am 24 Jun. 2022
Try something like this —
T1 = table(datetime('now') + days(sort(randperm(150, 20)))', randi(99,20,1), 'VariableNames',{'Time','Random'});
TT1 = table2timetable(T1)
TT1r = retime(TT1, 'regular', 'sum', 'TimeStep',days(10))
Here, there are two 10-day intervals in which there are no entries.
.
2 Kommentare
Star Strider
am 24 Jun. 2022
My pleasure.
That is incorrect.
The MATLAB date and time functions are remarkably robust. They do not take into account individual months with respect to the edges of the intervals for summation (in this instance). Here, the code sums over every 10 consecutive days as instructed, regardless of the days of the month. See the retime documentation for details.
.
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!