Finding yearly average of data in a matrix

4 ビュー (過去 30 日間)
Billy Dipre
Billy Dipre 2020 年 3 月 30 日
回答済み: dpb 2020 年 3 月 30 日
I have a 13459x2 matrix where the first column is the year the data was taken and the second column is the data value. The data was taken "daily" for each year but a lot of the years do not actually have the same number of data points. I was originally going through and looking for which rows the years started and ended and my code looked like this:
mean1978 = (sum(iceArea(1:34,2)))/34;
But this became really tedious considering this is over the course of 40 years and 13459 rows to sift through. So is there a way where I could just say something like
mean1978 = (sum(iceArea(==1978,2)))/ % # of rows ==1978;
so I just enter the year instead of finding the start and end rows?

採用された回答

dpb
dpb 2020 年 3 月 30 日
Of course there is..."grouping variables"
[meanByYear,yr,yrcounts]=groupsummary(iceArea(:,2),iceArea(:,1),'mean');

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by