# I want annual data from monthly data (sum of every 12 months)

2 views (last 30 days)
BN on 30 Mar 2020
Edited: Peng Li on 30 Mar 2020
Hey all,
I have a 1 x3 cell which contains 3 tables (360x3). In each table, there is a "dates" column (MM/DD/YYYY) and precipitation value (rrr24) column. The dates are for 30 years, monthly. Please help me to have another 1 x3 cell (newcell) which contains 30x3 tables with the amount of precipitation for each year instead of the month. I would like to use the sum function to convert monthly precipitation to annual.
I attached my cell.
Thank you so much.

Peng Li on 30 Mar 2020
Hi, you again lol and me again
I thought it would be easier for you to solve this with my previous answer regarding the season stuff.
newCell = cellfun(@cusFun, CELL, 'UniformOutput', 0);
function cusTbl = cusFun(tbl)
tbl.year = year(tbl.dates);
[grp, cusTbl] = findgroups(tbl(:, 'year'));
cusTbl.sum_rrr24 = splitapply(@sum, tbl.rrr24, grp);
cusTbl.grid_name = splitapply(@(x) x(1), tbl.(1), grp);
end
##### 2 CommentsShowHide 1 older comment
Peng Li on 30 Mar 2020
Edited: Peng Li on 30 Mar 2020
I'm working from home too because of the virus.

### Categories

Find more on Tables in Help Center and File Exchange

R2018b

### Community Treasure Hunt

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

Start Hunting!

Translated by