필터 지우기
필터 지우기

Synchronize two time series matlab R2015a

조회 수: 2 (최근 30일)
tilfani oussama
tilfani oussama 2018년 3월 2일
답변: tilfani oussama 2018년 3월 5일
I have two time series SP and CAC40 returns, i would like to save only equal dates values, i have a matlab 2015a. Bests

채택된 답변

Star Strider
Star Strider 2018년 3월 2일
Try this:
[D1,S1,R1] = xlsread('SP dated.xls');
[D2,S2,R2] = xlsread('CAC40 dated.xls');
S1ds = R1(2:end,:); % Valid ‘SP’ Data (Omitting Header)
S2ds = R2(2:end,:); % Valid ‘CAC40’ Data (Omitting Header)
dn1 = datenum(S1ds(:,1), 'yyyy-mm-dd'); % Convert To ‘Date Numbers’
dn2 = datenum(S2ds(:,1), 'yyyy-mm-dd'); % Convert To ‘Date Numbers’
[Dc, ia, ic] = intersect(dn1, dn2, 'stable'); % Common Date Numbers
SP = S1ds(ia,:); % ‘SP’ Result Matrix
CAC40 = S2ds(ic,:); % ‘CAC40’ Result Matrix
SP_First10 = SP(1:10,:); % Examine Output (Delete Later)
CAC40_First10 = CAC40(1:10,:); % Examine Output (Delete Later)
The code is straightforward, and the comments document what each line does. The 'stable' argument to the intersect call keeps everything in the original order rather than sorting it.
The sizes of the output arrays ‘SP’ and ‘CAC40’ are the same sizes (as they should be), and both less than the original of either of the original arrays, indicating that they now have only common dates. I looked at a range of them but not all, and the result appears to be what you want.
I included ‘SP_First10’ and ‘CAC40_First10’ to let you easily examine that range or any other range you want, to verify that the data are correct.
  댓글 수: 1
tilfani oussama
tilfani oussama 2018년 3월 5일
Thank you for your code, i get this message
Error using datenum (line 178)
DATENUM failed.
Caused by: Error using dtstr2dtnummx
Failed on converting date string to date number.

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

추가 답변 (1개)

tilfani oussama
tilfani oussama 2018년 3월 5일
That works with
[D1,S1,R1] = xlsread('SP dated.xls');
[D2,S2,R2] = xlsread('CAC40 dated.xls');
S1ds = R1(2:end,:);
S2ds = R2(2:end,:);
dn1 = datenum(S1ds(:,1), 'dd/mm/yyyy');
dn2 = datenum(S2ds(:,1), 'dd/mm/yyyy');
[Dc, ia, ic] = intersect(dn1, dn2, 'stable');
SP = S1ds(ia,:); % ‘SP’ Result Matrix
CAC40 = S2ds(ic,:);

카테고리

Help CenterFile Exchange에서 Calendar에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by