0
$\begingroup$

I have a list of x,y values and i am finding the distance between each point, So for 20 point in my file I have something like this,

AA = Import["/Users/Desktop/400xy.txt", "Data"];
ex = Table[Abs[AA[[i]][[1]] - AA[[j]]][[1]], {i, 1}, {j, 1, 20}];
yi = Table[Abs[AA[[i]][[2]] - AA[[j]]][[2]], {i, 1}, {j, 1, 20}];
sqrti = Table[Sqrt[ex^2 + yi^2], {i, 1}]

now it outputs

{{0., 16.1328, 33.04, 10.1404, 9.36833, 23.8291, 10.253, 19.3589, 
   33.5673, 17.0239, 17.629, 27.2732, 20.8989, 26.5407, 37.4516, 
   29.6398, 35.45, 34.4077, 36.3561, 44.6558}}}

Everything is good up to here, I want to use if condition to get only values less than 12 (without 0) and append them to a new list and I want to repeat this for all my points in the file I tried something like this:

listBo[i] = 
If[Table[Sqrt[ex^2 + yi^2], {i, 1}] < 12,
 AppendTo[listBo[i], j],
 Continue
 ]

the output then:

If[{{{0., 16.1328, 33.04, 10.1404, 9.36833, 23.8291, 10.253, 19.3589, 
     33.5673, 17.0239, 17.629, 27.2732, 20.8989, 26.5407, 37.4516, 
     29.6398, 35.45, 34.4077, 36.3561, 44.6558}}} < 12, 
 AppendTo[listBo[i], j], Continue]

Any help is appreciated.

$\endgroup$
  • 3
    $\begingroup$ Skipping all of the intermediate steps: Select[Norm /@ (AA[[1]] - # & /@ Rest[AA]), 0 < # < 12 &] $\endgroup$ – Bob Hanlon Feb 12 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.