MATLAB: How to get yearly sum values

cumulativesumyearly

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!

Best Answer

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)]