I have two lists in Mathematica:
list1 = {{a1, b1, c1}, ... , {an, bn, cn}}
and
list2 = {{d1, e1, f1}, ... , {dn, en, fn}}
the lists contain numerical results and are roughly consisting of 50000 triplets each. Each triplet represents two coordinates and a numerical value of some property at these coordinates. Each list has different length and the coordinates are not quite the same range. My intention is to correlate the numerical values of the third property from each list so I need to scan through the lists and identify the properties whose coordinates are matching. My output will be something like
list3 = {{ci, fj}, ... , {cl, fm}}
where
{ai, bi}, ..., {al, bl}
will be (roughly) equal to, respectively
{dj, ej}, ..., {dm, em}
By “roughly” I mean the coordinates will match once rounded to some desired accuracy:
list1(2) = Round[{#[[1]], #[[2]], #[[3]]}, {1000, 500, 0.1}] & /@ list1(2)
so after this process I’s have two lists that contain some matching coordinates amongst them. My question is how to perform the operation of identifying them and picking out the pairs of properties in the optimal way?
An example of a 6 element list would be
list1 = {{-1.16371*10^6, 548315., 14903.}, {-1.16371*10^6, 548322., 14903.9},
{-1.16371*10^6, 548330., 14904.2}, {-1.16371*10^6, 548337., 14904.8},
{-1.16371*10^6, 548345., 14905.5}, {-1.16371*10^6, 548352., 14911.5}}
You may want to use something like this:
This will group all data points that having matching coordinates after rounding. You can use a second argument to
Roundto specify the fraction to round by.This assumes that there are not duplicated points within a single list. If there are, you will need to remove those to get useful pairs. Tell me if this is the case and I will update my answer.
Here is another method using
SowandReap. The same caveats apply. Both of these examples are simply guidelines for how you may implement your functionality.To deal with duplicate-after-round elements within each list, you may use
RoundandGatherByon each list as follows.and then proceed with: