How can I do the cumulative?

1 view (last 30 days)
Pul
Pul on 25 Aug 2021
Commented: Star Strider on 26 Aug 2021
Hello everyone,
I should calculate the cumulative of daily data.
Then I should do a monthly cumulative and finally, the yearly average.
Can anyone help me please?
Thank you.
  4 Comments
Wan Ji
Wan Ji on 25 Aug 2021
Hi Pul,
I think Star Strider has offered good answer, you can do following his way.
Wan Ji
Pul
Pul on 25 Aug 2021
Yes, thank you!

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 25 Aug 2021
The retime function is your friend foir this type of problem —
LD = load('giulia_TT[1].mat');
giulia_TT = LD.giulia_TT
giulia_TT = 136440×6 timetable
Time Var1 Var2 Var3 Var4 Var5 Var6 ____________________ ____ ____ _____ ____ ____ _____ 10-Dec-1997 09:00:00 310 1 -27 43 NaN 712.9 10-Dec-1997 10:00:00 300 1 -28.4 47 NaN 712.7 10-Dec-1997 11:00:00 260 4 -30.3 48 NaN 712.8 10-Dec-1997 12:00:00 240 4 -32.4 49 NaN 712.6 10-Dec-1997 13:00:00 220 4 -34.5 50 NaN 712.3 10-Dec-1997 14:00:00 180 4 -31.4 52 NaN 712.3 10-Dec-1997 15:00:00 220 1 -31.3 53 NaN 712.1 10-Dec-1997 16:00:00 200 2 -29.9 53 NaN 712 10-Dec-1997 17:00:00 180 3 -29.4 54 NaN 711.7 10-Dec-1997 18:00:00 200 2 -29.1 54 NaN 711.5 10-Dec-1997 19:00:00 210 3 -28.9 54 NaN 711.4 10-Dec-1997 20:00:00 180 3 -28.7 54 NaN 711.4 10-Dec-1997 21:00:00 210 1 -28.3 54 NaN 711.3 10-Dec-1997 22:00:00 250 2 -28.1 55 NaN 711.3 10-Dec-1997 23:00:00 270 3 -28.2 55 NaN 711.4 11-Dec-1997 00:00:00 270 3 -27.9 55 NaN 711.3
RTds_giulia_TT = retime(giulia_TT,'daily', @(x)sum(x,'omitnan')) % Daily Sum
RTds_giulia_TT = 7722×6 timetable
Time Var1 Var2 Var3 Var4 Var5 Var6 ___________ ____ ____ ______ ____ ____ _____ 10-Dec-1997 3430 38 -445.9 775 0 10680 11-Dec-1997 4970 88 -708.9 1304 0 17079 12-Dec-1997 4770 190 -718.3 1265 0 17107 13-Dec-1997 4820 257 -593.6 1329 0 17118 14-Dec-1997 5130 223 -625.3 1276 0 17148 15-Dec-1997 6160 122 -610.4 1231 0 17301 16-Dec-1997 5330 282 -612.3 1254 0 17229 17-Dec-1997 4840 220 -631.3 1295 0 17226 18-Dec-1997 5210 171 -638.5 1294 0 17181 19-Dec-1997 5500 192 -662.9 1233 0 17175 20-Dec-1997 5900 149 -629.9 1242 0 17164 21-Dec-1997 5020 153 -615.8 1273 0 17345 22-Dec-1997 5500 331 -555.8 1315 0 17371 23-Dec-1997 5020 274 -579.6 1306 0 17275 24-Dec-1997 5090 220 -541.7 1338 0 17406 25-Dec-1997 5390 325 -542.8 1293 0 17477
RTms_giulia_TT = retime(giulia_TT,'monthly', @(x)sum(x,'omitnan')) % Daily Sum
RTms_giulia_TT = 254×6 timetable
Time Var1 Var2 Var3 Var4 Var5 Var6 ___________ __________ ____ _______ _____ _____ __________ 01-Dec-1997 1.1479e+05 4878 -12777 28071 0 3.732e+05 01-Jan-1998 1.6505e+05 4790 -20623 38684 0 5.3087e+05 01-Feb-1998 1.5418e+05 7953 -22694 35043 0 4.7948e+05 01-Mar-1998 1.5895e+05 8202 -16416 53622 0 5.0993e+05 01-Apr-1998 19780 1272 -1792.9 7235 0 64240 01-May-1998 0 0 0 0 0 0 01-Jun-1998 0 0 0 0 0 0 01-Jul-1998 0 0 0 0 0 0 01-Aug-1998 0 0 0 0 0 0 01-Sep-1998 0 0 0 0 0 0 01-Oct-1998 0 0 0 0 0 0 01-Nov-1998 15670 735 -2075.2 4977 1151 52008 01-Dec-1998 1.5947e+05 6713 -18695 51606 12188 5.3271e+05 01-Jan-1999 1.4317e+05 6176 -17875 55303 13262 5.3282e+05 01-Feb-1999 1.4437e+05 6296 -26016 40696 12270 4.8046e+05 01-Mar-1999 1.5873e+05 7751 -38321 34910 14902 5.2862e+05
RTym_giulia_TT = retime(giulia_TT,'yearly', @(x)mean(x,'omitnan')) % Yearly Average
RTym_giulia_TT = 23×6 timetable
Time Var1 Var2 Var3 Var4 Var5 Var6 ___________ ______ ______ _______ ______ ______ ______ 01-Jan-1997 221.18 9.3988 -24.618 54.087 NaN 719.08 01-Jan-1998 221.12 9.739 -31.197 62.76 16.347 712.16 01-Jan-1999 205.71 9.868 -38.546 60.084 27.833 709.86 01-Jan-2000 206.22 10.858 -40.587 58.32 42.214 712.57 01-Jan-2001 209.39 9.7574 -40.086 57.345 49.112 711.97 01-Jan-2002 209.49 11.56 -46.325 50.188 41.987 714.63 01-Jan-2003 204.8 13.667 -45.886 51.518 58.09 713.5 01-Jan-2004 216.18 10.512 -44.052 53.394 68.275 697.74 01-Jan-2005 212.52 11.821 -41.702 55.45 76.23 689.32 01-Jan-2006 209.99 10.875 -40.048 57.513 98.428 721.18 01-Jan-2007 210.15 9.7131 -39.308 58.263 96.873 747.83 01-Jan-2008 215.82 11.908 -40.737 56.545 73.186 711.08 01-Jan-2009 216.33 12.638 -41.397 56.284 78.298 711.96 01-Jan-2010 226.65 11.077 -47.59 49.562 75.023 710.05 01-Jan-2011 213.5 12.444 -44.61 54.425 90.797 713.36 01-Jan-2012 218.74 11.087 -41.803 56.673 101.93 713.02
Experiment to get different results.
.
  10 Comments
Pul
Pul on 26 Aug 2021
Thank you!
Star Strider
Star Strider on 26 Aug 2021
As always, my pleasure!
.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!