MATLAB: Can I merge two matrices of different length with respect to a date column contained in both

matrix manipulationmergetime series

I have two matrices each containing date numbers in the first and observations in the second column. I would like to merge them so that my new matrix only contains the dates present in both matrices and the matching observations – it should be a three column matrix [dates obsMatrix1 obsMatrix2]

Best Answer

Take a look at INTERSECT. Something along these lines could work:
[~,i,j] = intersect(A(:,1),B(:,1))
C = [A(i,:) B(j,2)]