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.
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.
n = 10;
x = rand(1,n);
y = rand(1,n);
评论
要发表评论,请点击 此处 登录到您的 MathWorks 帐户或创建一个新帐户。