How to get yearly sum values

2 次查看(过去 30 天)
Hi
I Have time variables, such as [01/04/1960(dd/mm/yyyy),23/09/1960, 08/01/1980, 18/11/1980] and corresponding magnitude values[5, 4.2, 6, 7]. I need yearly sum values of magnitudes. So for the year 1960 I am supposed to get 9.2, and for 1980 the value 13.(Actually my table is much bigger, I just gave 2 years values to know the way how to do it).
So how I can get yearly sum values?
Thank a lot!

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2016-5-20
d={'01/04/1960';'23/09/1960';'08/01/1980';'18/11/1980'}
v=[5; 4.2; 6;7]
a=datevec(d,'dd/mm/yyyy')
[y,~,kk]=unique(a(:,1))
out=[y accumarray(kk,v)]
  7 个评论
davit petraasya
davit petraasya 2016-5-20
Thank you Azzi for answering to this question also. You are very helpful.
Ice lady
Ice lady 2016-8-21
Dear Azzi,
I have a similar problem to davit and tried to re-write the above to work for me, but failed. My date data is in form YYYY = A(:,1), mm = A(:,2) and dd = A(:,3). My daily data has variable number of entries and is in column A(:,5). I also need to compute annual data totals.
Any suggestions would be greatly appreciated.
Thanks in advance

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by