MATLAB: Search an element in another matrix.

element search

Hello,
I am a newbie and thanks in advance for the help.
I have 2 matrix : one say A with size 217 * 2 and another one B with 10864 * 2 .
Both of theses arrays consists of a date column ( first one) and another column of data.
I need to find the common dates between these 2 matrix.
I have done an intersect between the 2 first columns and i got the common dates.
Now I need to take each of these dates and search in the first and the second matrix and offset it by one column to get the value of the second column on the common dates. In final, I will need to get a matrix with common dates, and 2 other columns corresponding to their values at the common dates.
I tried with a loop with find command, but i am getting an size mismatch which is normal, I also tried to reshape and normalize both arrays but its not working.
I did :
c = intersect(A(:,1),B(:,1) — Common Dates.
It gave me a matrix of 217 * 2 .
But then I am getting difficulties to search these values in the other 2 matrix.
Thanks for your help.
D

Best Answer

[c ia ib] = intersect(A(:,1),B(:,1));
c should be 217 x 1, as should ia & ib.
A(ia,:)
that should spit out the date & the value for all of the intersecting dates in A.
B(ib,:)
that should spit out the date & the value for all of the intersecting dates in B.