MATCH2
Name
MATCH2
Purpose
Routine to cross-match values in two vectors (including non-matches)
Explanation
This procedure *appears* similar to MATCH of the IDL astronomy
library. However, this routine is quite different in that it
reports an index value for each element of the input arrays.
In other words, while MATCH reports the *existence* of
matching elements in each array, MATCH2 reports explicitly
*which* elements match.
Furthermore, while MATCH reports only unique matching
elements, MATCH2 will always report a cross-match for every
element in each array, even if it is a repeat.
In cases where no match was found, an index of -1 is
reported.
Calling Sequence
match2, a, b, suba, subb
Inputs
a,b - two vectors to match elements, numeric or string data types
Outputs
suba - vector with same number of elements as A, such that
A EQ B[SUBA], except non-matches which are indicated
by SUBA EQ -1
subb - vector with same number of elements as B, such that
B EQ A[SUBB], except non-matches which are indicated
by SUBB EQ -1
Restrictions
The vectors A and B are allowed to have duplicates in them,
but for matching purposes, only the first one found will
be reported.
Example
A = [0,7,14,23,24,30]
B = [7,8,14,25,14]
IDL> match2, a, b, suba, subb
--> suba = [ -1 , 0, 4, -1, -1, -1 ]
(indicates that A[1] matches B[1] and A[3] matches B[2])
--> subb = [ 1 , -1, 2, -1, 2 ]
(indicates that B[1] matches A[1] and B[2] matches A[3])
Compare to the results of the original MATCH procedure,
IDL> match, a, b, suba, subb
--> suba = [ 1, 3]
(indicates that A[1] and A[3] match elements in B, but not which ones)
--> subb = [ 1, 2]
(indicates that B[1] and B[2] match elements in A, but not which ones)
Modification History
Derived from the IDL Astronomy Library MATCH, 14 Feb 2007
Updated documentation, 17 Jul 2007
More updated documentation (example), 03 Sep 2007