필터 지우기
필터 지우기

How to synchronize matrices (timeseries)?

조회 수: 1 (최근 30일)
Léon
Léon 2011년 9월 15일
May Somebody help me solve this problem?
I retrieved stock data from Yahoo and stored it in matrices, every matrix consists of 6 Columns (date,open,high,low,close,volume) and N time steps in the rows (daily).
conn = yahoo('http://download.finance.yahoo.com');
DBK=fetch(conn,'DBK.DE',{'Open', 'High', 'Low','Close','Volume'},'Jan 01 2005','Dec 31 2010', 'd')
DTE=fetch(conn,'DTE.DE',{'Open', 'High', 'Low','Close','Volume'},'Jan 01 2005','Dec 31 2010', 'd')
You will notice that both matrices do not have the same amount of rows DBK<1547x6>; DTE<1528x6>
Hence I cannot compare them, since there are some missing values in DTE. But since I got the date ID in column 1 of each matrix I would like to have the intersection between both matrices based on this ID. Can you help me? And is it possible to compute the intersection for more than 2 matrices?
Help is greatly appreciated!

채택된 답변

Léon
Léon 2011년 9월 15일
That is exactly what I need, but I have to find the intersection between more than 2 matrices. :-( I tried to use the intersect() command iterative (intersection between A/B, B/C, C/D,…) but this doesn't really work.
Do you have another hint for me, please?
  댓글 수: 1
Fangjun Jiang
Fangjun Jiang 2011년 9월 15일
You can do one at a time, like
out=intersect(A,B);
out=intersect(out,C);
out=intersect(out,D);
or see http://www.mathworks.com/matlabcentral/fileexchange/30725-multiple-or-partial-intersect-function

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

추가 답변 (3개)

Fangjun Jiang
Fangjun Jiang 2011년 9월 15일
Did you try intersect()?
A=[(1:10)', rand(10,1)];
B=[(5:15)', rand(11,1)];
[C,IndA,IndB]=intersect(A(:,1),B(:,1));
A_Selected=A(IndA,:)
B_Selected=B(IndB,:)

Léon
Léon 2011년 9월 16일
Thank you that was exactly the point!

Léon
Léon 2011년 9월 26일
I have a follow-up question and I hope you can help me again:
I tried to solve this problem using loops and stored the data in cell arrays. Applying your code to that did not quite work, since I managed to get the intersection of all time-series, but now I want to reduce all matrices based upon this intersection:
% N = number of time-series
for n = 1:N,
% Get the intersection of all time-series (date is stored in column 1)
AnB = intersect(data{n,1}(:,1),data{n,1}(:,1));
end;
for n = 1:N,
% Now I want to "delete" all rows that are not part of the intersection
% But of course I want to have all columns with the data in it and not only the date column
[c, a, b] = intersect(AnB(:,1),data{n,1}(:,1));
data{n,1} = data{n,1}(a,:); % --> this gives the error
end;
Thank you very much for helping me!
  댓글 수: 2
Fangjun Jiang
Fangjun Jiang 2011년 9월 26일
Please post this as a separate question.
And you need to take a second look at the question. None of the variable N, data are given so others won't be able to run the code.
What is AnB = intersect(data{n,1}(:,1),data{n,1}(:,1))?
Do you mean AnB = intersect(data{n,1}(:,1),data{n,2}(:,1))?
Léon
Léon 2011년 9월 26일
OK, sorry for that. I opened a new question: http://www.mathworks.de/matlabcentral/answers/16786-intersection-of-multiple-time-series and reworked the code.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by