How to decide a node in an overlapped area to select which base station

I have attached the pic, i have 200 nodes in this scenario and randomly located base stations. In the overlapped area, i want the nodes to calculate the distance between their location and base stations and then decide the shortest path , How can i do that , any ideas? Thank you in advance

4 件のコメント

Glo
Glo 2015 年 1 月 15 日
are the nodes static?
Cladio Andrea
Cladio Andrea 2015 年 1 月 15 日
Yes exactly
Maira Imran
Maira Imran 2017 年 4 月 21 日
Cladio Andrea can you please share the code of this figure?
Image Analyst
Image Analyst 2017 年 4 月 21 日
Maira, try this:
% Create the cyan x's.
numNodes = 200;
nodeX = 200 * rand(1, numNodes);
nodeY = 40 * rand(1, numNodes);
% Plot them
plot(nodeX, nodeY, 'cx', 'MarkerSize', 7);
grid on;
axis equal;
xlabel('X', 'FontSize', 20);
ylabel('Y', 'FontSize', 20);
xlim([0, 200]);
ylim([0, 40]);
% Create the green spots.
numBases = 8;
baseX = 200 * rand(1, numBases);
baseY = 40 * rand(1, numBases);
hold on;
plot(baseX, baseY, 'g.', 'MarkerSize', 25);
% Create the dark blue circles.
numDarkBlueCircles = 23;
blueX = 200 * rand(1, numDarkBlueCircles);
blueY = 40 * rand(1, numDarkBlueCircles);
hold on;
plot(blueX, blueY, 'bo', 'MarkerSize', 7);
% Create the yellow circles.
centers = [baseX', baseY']
radii = 20 * ones(numBases, 1)
% Plot the yellow circles.
viscircles(centers, radii, 'Color', 'y', 'LineWidth', 2);

サインインしてコメントする。

 採用された回答

Image Analyst
Image Analyst 2015 年 1 月 15 日
Just use the Pythagorean theorem to calculate distances
distances = sqrt((thisX - baseStationXs).^2 + (thisY - baseStationsYs).^2);
% Find the closest one
[closestDistance, indexOfClosestBaseStation] = min(distances);
Not really sure what you mean by "shortest path" but that will give you the index of the base station that is closest to your "test" point.

1 件のコメント

Image Analyst
Image Analyst 2015 年 1 月 15 日
For a discussion on shortest paths, see Steve's blog. http://blogs.mathworks.com/steve/2011/11/01/exploring-shortest-paths-part-1/
If you mean path, as in the Traveling Salesman Problem, then search the Answers forum or MATLAB Central for that or for "TSP".

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by