Stuart’s MATLAB Videos

Watch and Learn

MATLAB Puzzler: Finding the two closest points

Here is a new MATLAB Puzzler. Given two vectors representing the X and Y coordinates of some points, find the two closest points in Cartesian space. n = 10; x = rand(1,n); y = rand(1,n);



Brett and I took very different paths to solving this problem, he knows more about the statistics toolbox than I do and found a much shorter solution because there is a function that basically does this. As a benchmark. sticking with base MATLAB, I solved this in seven lines of code. Post your solutions in the comments area along with how long it took you to solve.
|
  • print

Comments

To leave a comment, please click here to sign in to your MathWorks Account or create a new one.