MATLAB: How to get cumulative sum in yearly buckets

cumulative sum

I have several years of data and temperature in one table. I want to calculate a cumulative temperature sum which I've done simply as A.CumulativeTemp= cumsum(A.Temp);
My question is, how can get a cumulative temp for each year, i.e. so it gives a cumulative temperature for the entire 2016, then starts again at zero in the same column and does the same for 2017 and so on?
Kind regards, Wendy

Best Answer

How about the following ?
% Read the data file and delete the answer column
opts = detectImportOptions('Reset Accum temp.xls');
T = readtable('Reset Accum temp.xls',opts);
T.AccumulatedTemperatureOfEachYear = []; % Remove the answer
% Apply cumsum function for each Year
T2 = varfun(@cumsum,T,'GroupingVariables','Year');
T = [T T2(:,'cumsum_Temperature')];