MATLAB Answers

Finding closest point to known coordinates

8 views (last 30 days)
Hi,
I want to find a coordinate which has minimum distance to other coordinates,
For example;
I want to find a coordinate (a,b) which has minimum distance to coordinates given below
x y
1 2
1 4
3 2
4 2

  1 Comment

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 20 Mar 2019
The minimum distance of a set of points is the Centroid (link), defined as the mean of the coordinates of the points:
xy = [1 2
1 4
3 2
4 2];
minDist = mean(xy);
figure
plot(xy(:,1), xy(:,2), 'pg')
hold on
plot(minDist(1), minDist(2), 'rp')
hold off
grid
axis equal
Experiment toi get the result you want.

  6 Comments

Show 3 older comments
Star Strider
Star Strider on 21 Mar 2019
As always, my pleasure.
Use the ‘idx’ value:
newVar = xy(idx,:)
producing:
newVar =
3 2

Sign in to comment.

More Answers (0)

Sign in to answer this question.