Cumulative sum of time series into one plot

조회 수: 5 (최근 30일)
Marko Rajkovic
Marko Rajkovic 2018년 12월 3일
댓글: Jan 2018년 12월 3일
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.
Jan
Jan 2018년 12월 3일
Does this mean, that you want an area() plot? See: https://www.mathworks.com/help/matlab/ref/area.html

댓글을 달려면 로그인하십시오.

답변 (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