bio_img_videos

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);
Video Player is loading.
Current Time 0:00
Duration 0:57
Loaded: 0%
Stream Type LIVE
Remaining Time 0:57
 
1x
  • Chapters
  • descriptions off, selected
  • captions off, selected
  • en (Main), selected


    Video Player is loading.
    Current Time 0:00
    Duration 5:18
    Loaded: 0%
    Stream Type LIVE
    Remaining Time 5:18
     
    1x
    • Chapters
    • descriptions off, selected
    • captions off, selected
    • en (Main), selected

      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.

      Loading...