One possibility is to use Association
. Here is a small example:
SeedRandom[1]
d1 = Thread[{Range[10], RandomReal[1, 10]}]
d2 = Thread[{Range[10], RandomReal[1, 10]}]
{{1, 0.817389}, {2, 0.11142}, {3, 0.789526}, {4, 0.187803}, {5, 0.241361}, {6,
0.0657388}, {7, 0.542247}, {8, 0.231155}, {9, 0.396006}, {10, 0.700474}}
{{1, 0.211826}, {2, 0.748657}, {3, 0.422851}, {4, 0.247495}, {5,
0.977172}, {6, 0.825163}, {7, 0.925275}, {8, 0.578056}, {9, 0.29287}, {10,
0.208051}}
Convert to an Association
object:
a1 = AssociationThread @@ Transpose @ d1
a2 = AssociationThread @@ Transpose @ d2
<|1 -> 0.817389, 2 -> 0.11142, 3 -> 0.789526, 4 -> 0.187803, 5 -> 0.241361,
6 -> 0.0657388, 7 -> 0.542247, 8 -> 0.231155, 9 -> 0.396006, 10 -> 0.700474|>
<|1 -> 0.211826, 2 -> 0.748657, 3 -> 0.422851, 4 -> 0.247495, 5 -> 0.977172,
6 -> 0.825163, 7 -> 0.925275, 8 -> 0.578056, 9 -> 0.29287, 10 -> 0.208051|>
Now, when we subtract 2 Association
objects, we get a new Association
object where the values are the differences between the values of each individual Association
. So:
r = a1 - a2
<|1 -> 0.605564, 2 -> -0.637237, 3 -> 0.366675, 4 -> -0.0596916,
5 -> -0.735811, 6 -> -0.759424, 7 -> -0.383029, 8 -> -0.346902,
9 -> 0.103136, 10 -> 0.492423|>
Plotting an Association
is simple:
ListPlot[r]
MapThread[(({Mean[#1], Subtract @@ #2} &) @@ Transpose[##]) &, {list1, list2}]
, I guess. (I'm not at a computer to check.) $\endgroup$p={{x1,y1},{x2,y2}}; q={{x1,Y1},{x2,Y2}};f[r_,s_]:={r[[1]],r[[2]]-s[[2]]}; MapThread[f,{p,q}]
$\endgroup$