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

조회 수: 2 (최근 30일)
BN
BN 2020년 3월 30일
편집: Peng Li 2020년 3월 30일
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
Peng Li 2020년 3월 30일
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
BN
BN 2020년 3월 30일
Dear Peng Li
Thank you so much. I never forget your precious help at this moment that my university is closed and quarantine restricts my contact ways.
Be healthy
Best regards?
Peng Li
Peng Li 2020년 3월 30일
편집: Peng Li 2020년 3월 30일
Thanks Behzad Navidi. Stay safe!
I'm working from home too because of the virus.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by