Cumulative sum of time series into one plot
4 views (last 30 days)
Show older comments
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 Comments
Jan
on 3 Dec 2018
Does this mean, that you want an area() plot? See: https://www.mathworks.com/help/matlab/ref/area.html
Answers (0)
See Also
Categories
Find more on Time Series in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!