title: Given a set of data points, find the one that is "closest"
body: <p>So we have a reference set of 3D points (let's call it R), and many other sets of 3D points (let's call that set of sets of data points P, and each data set in that Pi).</p>
  
  <p>The task is to return the Pi that minimizes the euclidean distance the data points in some Pi and R. The way I see it is this:</p>
  
  <ol>
  <li>For each point in Pi, compare to each point in R and find the minimum difference between two points.</li>
  <li>Sum up these minimum distances to reach the minimum total "difference" between Pi and R.</li>
  <li>The answer Pi is the one with the smallest difference.</li>
  </ol>
  
  <p>But this is pretty crazy, since it means essentially looking at the distance between every point in R and every point in P, which could be thousands or millions. Surely I can do better than that.</p>
  
  <p>I am working in Matlab, which I am not used to. </p>
  
  <p>What is a better algorithm to use? Is there a data structure that is perfect for this? (for example a K-D tree?)</p>