フィルターのクリア

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 Center および File ExchangeCalendar についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by