简体   繁体   中英

Plot time series of different length in Matlab

Using Matlab I would like to plot the returns of five indices stored in a 11933x5 double (Data2). The problem ist, that the series are of different length, meaning for four of the five indices the first data points are not available. I guess this is why the following code only plots one series

dates = Data(:,1);
MATLABdates = x2mdate(dates);

MSCI = Data(:,2);
SaP = Data(:,5);
BRIC = Data(:,6);
HFRX = Data(:,9);
LPX = Data(:,10);

Data2 = horzcat(MSCI,SaP, BRIC, HFRX, LPX);

datetext = datestr(MATLABdates); 
datetext = cellstr(datetext);

DataT = table(MSCI,SaP,BRIC,HFRX,LPX);
DataT.Properties.RowNames = datetext;

Series = DataT.Properties.VariableNames;

figure
plot(MATLABdates, ret2price(price2ret(Data2)))
datetick('x')
xlabel('Date')
ylabel('Index Value')
title ('Relative Daily Index Closings')
legend(Series, 'Location', 'NorthWest')

This is the resulting plot: 在此处输入图片说明

the four shorter series are missing.

Does anyone know what I have to do to see all of the series (some of them just starting a little bit later?

Thanks a lot!

you can use:

hold on
plot(x1,y1)
plot(x2,y2)
....
plot(nx,yn)
hold off

or simply
plot(x1,y1,'r',x2,y2,'b',....xn,yn,'<line options>')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM