How to identify biggest location plot of random plotting

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);

 Accepted Answer

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 Comments

I also used knnsearch but only get 1 point. And also use rangesearch and dsearchn but did not get desired output.
From the code, do you have a way to cover the area at the end where the node plotted? I need to create 1 node among them to be able communicate with BS point. Because I need to cover each node by make a group for them and select one node to communicate to BS point.
Thank you
For knnsearch you need to specify the number of points you want, default is one thats why, you got only one point. Can you elaborate more on what you expect?
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.
Thank you for your tips knnsearch. Thankyou.

Sign in to comment.

More Answers (0)

Asked:

on 12 Jan 2021

Commented:

on 11 Feb 2021

Community Treasure Hunt

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

Start Hunting!