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);
0 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!