1
$\begingroup$

How can I substitute the arrays of a list to the frameCenter1 variable in the following Do loop? I used frameCenter1[[i]] but no answer. Assume frameCenter1 can be selected from this list: frameCenter1 = {{1, 10}, {7, 10}, {9, 4}}

dalist = {{9, 6}, {5, 6}, {6, 0}, {0, 5}, {10, 8}, {1, 2}, {10, 
   4}, {1, 1}, {7, 7}, {6, 8}, {5, 3}, {6, 9}, {7, 4}, {1, 8}, {10, 
   0}, {10, 7}, {6, 3}, {4, 0}, {9, 2}, {4, 7}, {1, 6}, {10, 8}, {7, 
   8}, {0, 9}, {3, 4}, {0, 0}, {8, 5}, {4, 5}, {6, 0}, {2, 9}, {2, 
   4}, {8, 4}, {7, 4}, {3, 6}, {7, 9}, {1, 9}, {1, 4}, {8, 0}, {8, 
   9}, {5, 4}, {2, 5}, {2, 9}, {3, 1}, {0, 6}, {10, 3}, {9, 6}, {8, 
   7}, {7, 6}, {7, 3}, {8, 9}, {7.5, 9}, {6.5, 9}, {7, 9}, {1, 5}, {2,
    6}, {1, 10}, {0.5, 8}, {1.5, 8}, {0.5, 7}, {1.5, 7}, {0.5, 
   6}, {1.5, 6}, {0.5, 5}, {1.5, 5}, {0.5, 4}, {1.5, 4}, {0.5, 
   9}, {1.5, 9}, {1, 7}, {2, 8}, {7, 10}, {9, 4}, {8, 4}, {8, 3}, {9, 
   5}, {9, 3}, {7.5, 3}, {8.5, 3}, {9.5, 4}, {8.5, 4}, {9.5, 4}, {7.5,
    4}, {9.5, 4}}
frameCenter1 = {{1, 10}, {7, 10}, {9, 4}}
b1 = Do[
  Select[dalist, EuclideanDistance[#, frameCenter1[[i]]] < 2 &]
, {i, 3}]
$\endgroup$
3
  • $\begingroup$ What is the value of dalist? I ask because I cannot get your code to run. You are also probably better doing this without the "Do" loop. $\endgroup$
    – Mark R
    Jun 7, 2020 at 2:03
  • $\begingroup$ Would something like Function[{point}, Select[dalist, EuclideanDistance[#, point] < 2 &]] /@ frameCenter1 do the trick? $\endgroup$
    – MarcoB
    Jun 7, 2020 at 2:05
  • $\begingroup$ Thank you Mark, added dalist to the question. $\endgroup$ Jun 7, 2020 at 2:09

1 Answer 1

0
$\begingroup$

This will give you the coordinate you are checking and all values that meet the criteria that the Euclidean distance is less than 2:

b1 = With[{checkCoordinate = #}, {checkCoordinate, 
    Select[dalist, 
     EuclideanDistance[#, checkCoordinate] < 2 &]}] & /@ frameCenter1

It gives the coordinate you are checking as the first element and then all members of dalist that are within the criteria.

And if you really don't care what value of frameCenter1 you are checking, then simply do this:

b1=DeleteDuplicates[
 Flatten[With[{checkCoordinate = #}, 
     Select[dalist, EuclideanDistance[#, checkCoordinate] < 2 &]] & /@
    frameCenter1, 1]]
$\endgroup$
2
  • $\begingroup$ Thank you, Mark! I like the 2nd approach. Could you please explain why did you use With. I am asking as when I check the functionality of With on Mathematica website. It substitutes checkcoordinate variable with #. Then how it knows the difference between # and CheckCordinate in the Select function? Sorry, I do not understand the approach. $\endgroup$ Jun 7, 2020 at 18:13
  • $\begingroup$ Hi Mehdi, I use "With" because I get confused at times about what "slot" (the "#") I'm filling in more complicated expressions. With simply lets me assign each of the elements of frameCenter1 to a reasonable name, checkCoordinate, and then use this in the Select. The "#" inside the Select references the pure function that is created as part of the Select. Written the way it is, Select fills the "#" slot with each of the elements in dalist. If this isn't clear, let's move this to chat - I'm happy to explain the approach in more detail. $\endgroup$
    – Mark R
    Jun 8, 2020 at 19:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.