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 日

1 投票

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 日
Great Azzi. You saved me once more :). Thank you very much!
davit petraasya
davit petraasya 2016 年 5 月 20 日
Azzi the code is working perfectly for single plot. If I want to use in plotyy it is not working
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)];
bar(y, accumarray(kk,v));
hold on;
plotyy(nan,nan,dateseries,values)
Here dateseries is (01/01/1965,08/04/1975,03/08/1985) and values correspondly (65,79,85).
What would be error?
Thanks.
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 5 月 20 日
What do you mean by : it's working for single plot?
davit petraasya
davit petraasya 2016 年 5 月 20 日
it is working for
bar(y, accumarray(kk,v));
if I want to continue my coding for making bar and curve together in one plot using by plotyy it is not working.
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 5 月 20 日
This is another question which is not related to your original question:
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,ii,kk]=unique(a(:,1));
out=[y accumarray(kk,v)];
yyaxis left
bar(datenum(d(ii)), accumarray(kk,v))
d1={'01/01/1965';'08/04/1975';'03/08/1985'}
vc=[65,79,85]
yyaxis right
plot(datenum(d1),vc)
xt=sort(datenum([d(ii);d1]))
set(gca,'xtick',xt)
datetick('x','yyyy','keepticks')
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 件)

カテゴリ

ヘルプ センター および File ExchangeTwo y-axis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by