Finding index into an nx2 matrix that is close to a 1x2 vector.

I have an nx2 matrix of latitude and longitude values that represents the route of a car. I also have a latitude/longitude for a point near that route. I want to find the index into the matrix that is closest to the point near the route.
Any suggestions?
NOTE: I used latitude and longitude to better explain the problem. The values aren't really lat/long.

 채택된 답변

Jan
Jan 2011년 10월 13일
search = [0.3, 0.5];
data = rand(100, 2);
nData = size(data, 1);
dist = sum((data - search(ones(nData,1), :)) .^ 2, 2);
[minDist, minIndex] = min(dist);

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

질문:

2011년 10월 13일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by