MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Need to reduce 2 lists so that only {x,y} pairs with same x remain


In article <8jc73k$dg3 at smc.vnet.net>, materialsscientist at my-deja.com 
wrote:

> I have 2 lists of data:
> 
> for example
> data1={{1,1},{1.5,1.5},{2,2},{3,3},{4,4},{5,5}}
> 
> data2={{1,2},{2,3},{3,4},{4,5},{6,7},{7,8}}
> 
> 
> I want to do a point by point comparision, so I
> need to reduce both data1 and data2 so that
> common x data in the {x,y} pairs for each list
> remain.
> 
> Thus the lists should look like this:
> 
> data1={{1,1},{2,2},{3,3},{4,4}}
> data2={{1,2},{2,3},{3,4},{4,5}}
> 
> What function(s) would to something like this?

   data1={{1,1},{1.5,1.5},{2,2},{3,3},{4,4},{5,5}}
   
   data2={{1,2},{2,3},{3,4},{4,5},{6,7},{7,8}}

You are basically after the Intersection of the (common x data) of two 
sets. You can use the SameTest option: 

   SetOptions[Intersection, SameTest -> (#1[[1]] == #2[[1]] & )];

and then

   {data1, data2} = 
      {Intersection[data1, data2], Intersection[data2, data1]}

Cheers,
   Paul

-- 
Paul Abbott                                   Phone: +61-8-9380-2734
Department of Physics                           Fax: +61-8-9380-1014
The University of Western Australia                
Nedlands WA  6907                      
AUSTRALIA                             http://physics.uwa.edu.au/~paul


  • Prev by Date: Re: List of patterns for which a function is defined?
  • Next by Date: Re: Problems with Legendre expansion
  • Previous by thread: Getting number out of NDSolve
  • Next by thread: 3d-2d points