I am trying to find nearest node from the fixed node.
so here is the code
x1= [16,38,56,78,45];
y1 =[23,62,77,56,34];
x2 = 100*rand(20,1);
x2= 150*rand(20,1);
for i = 1:5
text(x1(i),y1(i),num2str(i))
end
for i= 1:20
text(x2(i), y2(i),num2str(i));
end
Now i have to find out the nearest node of [x1,y1] w.r.t [x2,y2]
Objective find out which 10nodes from [x2,y2] are near to the [x1,y1] node

 채택된 답변

Walter Roberson
Walter Roberson 2018년 12월 9일

0 개 추천

pdist2

댓글 수: 6

Sushree Patra
Sushree Patra 2018년 12월 9일
Thank you sir for the response. But pdist2 is calculate the distance btween two sets . How it will find neighbor node of [x1,y1]
Bruno Luong
Bruno Luong 2018년 12월 9일
Select set 1 contains the first point set 2 contains the other points.
Walter Roberson
Walter Roberson 2018년 12월 9일
let the first set be just the one point . Then min() on the result
Thank you sir for the response.
can you please explain how to use that min() in my code
means if
x1=16
y1=23
x2=100*rand(20,1)
y2=100*rand(20,1)
then which pont of that random number of 1-20 is nearest (16,23) coordinator point.
dd = pdist2([x1 y1], [x2 y2]);
[~, idx] = min(dd);
xclosest = x2(idx);
yclosest = y2(idx);
... I feel like I just did someone's homework for them because they did not read the documentation .
Sushree Patra
Sushree Patra 2018년 12월 9일
Thank you very much sir Walter for you response and Solutions.
Well, Sir these quarries are related to my project based on Global optimization by using free search krill herd algorithm and opposition based learning.
As I am new to the Matlab and joined before 1 to 2 months seek help to implement my problem.
Much Appreciated
Thank you

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

태그

질문:

2018년 12월 9일

댓글:

2018년 12월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by