Cumulative sum of time series into one plot

4 次查看(过去 30 天)
Hello eveyone, the following relies on the following Exchange file: downloaded GDP data for selected countires:
startDate = strcat('1996-01-01');
endDate = strcat('2017-12-31');
[calDate, GDPdeu]=fred2read('DEUGDPNQDSMEI',startDate,endDate);
[~, GDPfra]=fred2read('FRAGDPNQDSMEI',startDate,endDate);
[~, GDPita]=fred2read('ITAGDPNQDSMEI',startDate,endDate);
[~, GDPesp]=fred2read('ESPGDPNQDSMEI',startDate,endDate);
[~, GDPaut]=fred2read('AUTGDPNQDSMEI',startDate,endDate);
[~, GDPbel]=fred2read('BELGDPNQDSMEI',startDate,endDate);
[~, GDPfin]=fred2read('FINGDPNQDSMEI',startDate,endDate);
[~, GDPirl]=fred2read('IRLGDPNQDSMEI',startDate,endDate);
[~, GDPlux]=fred2read('LUXGDPNQDSMEI',startDate,endDate);
[~, GDPnld]=fred2read('NLDGDPNQDSMEI',startDate,endDate);
[~, GDPprt]=fred2read('PRTGDPNQDSMEI',startDate,endDate);
for i=0:21
calDateYear(i+1) = calDate(4*i+2);
GDPdeuYear(i+1) = 1000000* (GDPdeu(4*i+1)+GDPdeu(4*i+2)+GDPdeu(4*i+3)+GDPdeu(4*i+4));
GDPitaYear(i+1) = 1000000* (GDPita(4*i+1)+GDPita(4*i+2)+GDPita(4*i+3)+GDPita(4*i+4));
GDPfraYear(i+1) = 1000000* (GDPfra(4*i+1)+GDPfra(4*i+2)+GDPfra(4*i+3)+GDPfra(4*i+4));
GDPespYear(i+1) = 1000000* (GDPesp(4*i+1)+GDPesp(4*i+2)+GDPesp(4*i+3)+GDPesp(4*i+4));
GDPautYear(i+1) = 1000000* (GDPaut(4*i+1)+GDPaut(4*i+2)+GDPaut(4*i+3)+GDPaut(4*i+4));
GDPbelYear(i+1) = 1000000* (GDPbel(4*i+1)+GDPbel(4*i+2)+GDPbel(4*i+3)+GDPbel(4*i+4));
GDPfinYear(i+1) = 1000000* (GDPfin(4*i+1)+GDPfin(4*i+2)+GDPfin(4*i+3)+GDPfin(4*i+4));
GDPirlYear(i+1) = 1000000* (GDPirl(4*i+1)+GDPirl(4*i+2)+GDPirl(4*i+3)+GDPirl(4*i+4));
GDPluxYear(i+1) = 1000000* (GDPlux(4*i+1)+GDPlux(4*i+2)+GDPlux(4*i+3)+GDPlux(4*i+4));
GDPnldYear(i+1) = 1000000* (GDPnld(4*i+1)+GDPnld(4*i+2)+GDPnld(4*i+3)+GDPnld(4*i+4));
GDPprtYear(i+1) = 1000000* (GDPprt(4*i+1)+GDPprt(4*i+2)+GDPprt(4*i+3)+GDPprt(4*i+4));
end
Basically, I created new vairable showing yearly rather than quarterly GDP.
Now I want to show the shares of each country's GDP graphically, compared to the overall amunt of the GDP. What i would like to do is to plot GDPdeuYear(i+1), GDPdeuYear(i+1) + GDPitaYear(i+1), ... In order to "add up* the plot of every country. But I am not very successfull in doing it. I'm also aware that there should be a more elegant way to do it. Additionaly, it would be nice to have a (differently) colored area under each line to make comparison possible. Can anyone help me?
  3 个评论
Marko Rajkovic
Marko Rajkovic 2018-12-3
@Jan by that part I mean:
If I just plot every country's GDP the upper curve shows the time-series for the country that has the highest GDP. Instead, the upper curve should diplay the sum of all GDPs. Here is an example.Schermata 2018-12-03 alle 19.11.47.png
What I need instead is:
Schermata 2018-12-03 alle 19.10.19.png
Here you can see that if a color covers a bigger area, then this is a signal that that country has a bigger share of the overall GDP.

请先登录,再进行评论。

回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by