I have 2 matrices with the SAME IDs. I need to extract those rows of IDs from mat1
which have their dates within say ±5 days of the dates in the mat2
. Same operation for mat2
as well. Please see the data here: UNIQCols = [1 2] ; dateCol = [3] ; valueCol = [4] ; dayRange = +- 15days
.
% UniqCol Date Value
mat1 = [2001 2 733427 1001 ;
2001 2 733793 2002 ;
2001 2 734582 2003 ;
3001 1 734220 30 ;
3001 1 734588 20 ;];
mat2 = [2001 2 733790 7777 ;
2001 2 734221 2222 ;
3001 1 734220 10 ;
3001 1 734588 40 ;] ;
ans1 = [2001 2 733793 2002 ; 3001 1 734220 30 ; 3001 1 734588 20 ] ;
ans2 = [2001 2 733790 7777 ; 3001 1 734220 10 ; 3001 1 734588 40 ] ;
This needs to be a vectorized operation! The IDs are ordered in increasing order of dates. Dates are either separated on Q or Annual basis. So the range will be always << (date2-date1) Please help and thanks!