1
$\begingroup$

I have something like this

tes1 = {{1, 2}, {0, 2}, {5, 10}}; tes2 = {{0, 2}, {5, 5}, {1, 2}}; Table[{If[tes1[[i]] == tes2[[j]], tes1[[i]], Null ]}, {j, 1, Length[tes1]}, {i, 1, Length[tes1]}] 

If I use Print[tes1[[i]]] instead of tes1[[i]] inside the "If", I got what I need, that is {0,2} and {1,2} only. But I want to convert in a list {{0,2},{1,2}}, how could I do that?

Edit1: In special, for the lists in https://pastebin.com/r4eCV5vT

If you compare them with Intersection, you will find that some points are not being compared. points The figure shows two red points, obtained from Intersection and you can see that there is two missed points (actually there is more points that both lists have in common), indicated with arrows.

Edit2: Doing

PtsDown = Table[SetAccuracy[Downn[[i, j]], 3], {i, 1, Length[Downn]}, {j, 1, 2}]; PtsUpp = Table[ SetAccuracy[Upp[[i, j]], 3], {i, 1, Length[Upp]}, {j, 1, 2}]; Table[{If[PtsDown[[i]] == PtsUpp[[j]], Print[PtsDown[[i]]],]}, {j, 1, Length[PtsUpp]}, {i, 1, Length[PtsDown]}] 

Gives

{0.*10^-3,8.66} {0.*10^-3,8.66} {4.50,2.60} {4.50,2.60} {7.50,9.53} {12.00,3.46} {12.00,3.46} {15.00,10.39} {15.00,10.39} 

The problem is that I need to copy the points without the repeated ones, after that, we got enter image description here

Or using the suggestion

 Select[PtsUpp, MemberQ[PtsDown, #] &] 

Gives

{{0.*10^-3, 8.66}, {0.*10^-3, 8.66}, {4.50, 2.60}, {7.50, 9.53}, {12.00, 3.46}, {12.00, 3.46}, {15.00, 10.39}} 
$\endgroup$
4
  • 2
    $\begingroup$ Intersection?....reference.wolfram.com/language/ref/Intersection.html $\endgroup$ Commented Oct 23, 2019 at 17:36
  • $\begingroup$ I tried but it fails. $\endgroup$ Commented Oct 26, 2019 at 6:32
  • $\begingroup$ What do you get when you execute Intersection[Downn, Upp] in your version/os? I get 4 points: {{4.5, 2.59808}, {7.5, 9.52628}, {12., 3.4641}, {15., 10.3923}} both in v12.0 (Wolfram Cloud) and v9.0 (windows 10). $\endgroup$ Commented Oct 26, 2019 at 6:45
  • $\begingroup$ Only two points {{7.5, 9.52628}, {15., 10.3923}}. Actually, there are 5 points, as you may notice near from x=0 and y~8 (I guess {-8.88178*10^-16, 8.66025}) one blue point is right under the green one in my picture. So I think we need a function that approximate the numbers, not like "Round" but something with more precision. $\endgroup$ Commented Oct 26, 2019 at 16:53

1 Answer 1

1
$\begingroup$
Intersection[tes1, tes2] 

{{0, 2}, {1, 2}}

Select[tes1, MemberQ[tes2, #] &] 

{{1, 2}, {0, 2}}

Update: Using the lists Downn and Upp from OP's link:

Intersection[Downn, Upp] 

{{4.5, 2.59808}, {7.5, 9.52628}, {12., 3.4641}, {15., 10.3923}}

ListPlot[{Downn, Upp, Intersection[Downn, Upp]}, PlotStyle -> {Directive[Opacity[.7], AbsolutePointSize[5], Green], Directive[Opacity[.7], AbsolutePointSize[5], Blue], Directive[Opacity[.7], AbsolutePointSize[10], Red]}, ImageSize -> Large, PlotLabel -> Row[{"intersection = ", ToString@Intersection[Downn, Upp]}]] 

enter image description here

$Version 

"12.0.0 for Linux x86 (64-bit) (April 7, 2019)"

$\endgroup$
3
  • $\begingroup$ Neither Intersection nor the other suggestion works in my lists. I made an edit on the post with the lists. $\endgroup$ Commented Oct 26, 2019 at 6:33
  • $\begingroup$ @Lucas, Intersection[Downn, Upp] gives 4 points: {{4.5, 2.59808}, {7.5, 9.52628}, {12., 3.4641}, {15., 10.3923}} (both in v12.0 (Wolfram Cloud) and v9.0 (windows 10)). What are you getting? $\endgroup$ Commented Oct 26, 2019 at 6:41
  • $\begingroup$ Only two points {{7.5, 9.52628}, {15., 10.3923}}. Actually, there are 5 points, if you look to your picture at x=0 and y=near above 8 (I guess {-8.88178*10^-16, 8.66025}), a green point is missing under the blue one. So I think we need a function that approximate the numbers, not like "Round" but something with more precision. $\endgroup$ Commented Oct 26, 2019 at 16:53

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.