How to identify biggest location plot of random plotting

1 次查看(过去 30 天)
I have a random plot and distance calculation. How can I identfy and inform the nodes which has a largest plot data to create one node in the middle of the group.
I know the distance of the node from A to BS. But I cant figure how to tell other node of A which location has many nodes and create 1 middle node but still close to BS.
I tried using range, min and max but the result only show which is far or close to the BS.
n = 50;
A =rand (n,2)*5;
BS = [2.5 2.5];
Dist = sqrt(sum((BS - A) .^ 2, 2));
plot(A(:,1), A(:,2), '.'); hold on %random plot
plot(BS(:,1), BS(:,2), '*','MarkerSize',10);

采纳的回答

KSSV
KSSV 2021-1-12
You need to sort the distance and pick the required number of points you want, to get the points from A close to BS.
n = 50;
A =rand (n,2)*5;
BS = [2.5 2.5];
Dist = sqrt(sum((BS - A) .^ 2, 2));
% Sort the Distance to get nodes closer to BS
[val,idx] = sort(Dist) ;
% pick first ten points from A close to BS
P = A(idx(1:10),:) ;
% get mean
Q = mean(P,2) ;
% plot
plot(A(:,1), A(:,2), '.r'); hold on %random plot
plot(BS(1), BS(2), '*b','MarkerSize',10);
plot(P(:,1), P(:,2), 'ok');
plot(Q(1),Q(2),'*r')
You can also have a look on inbuilt finction knnsearch which is exclusively made to get the nearest neighbors.
  4 个评论
wan asma
wan asma 2021-1-12
yes. I need to produce a random node(A) and 1 fix point(BS). After that, I need to find 1 node among the random plot which can form a group of node and located near to point BS. As the random plot are randomly plot, it may produce more than 1 group of node.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by