Find Shortest Path in Coordinate based Multiple Circle Using Rand

I want to find shortest path between nodes using rand.i just able to draw nodes, connecting nodes.. Bt i am stuck when i want to find the shortest path Between them. I already seen many topic in mathworks Related this topic but all off them are for fix value but i want randomly. Please help me.. my code is below here
clc clear all
X = randi(10,5,1);
Y = randi(10,5,1);
centers = [X Y];
radius =10*ones(1,5);
base_x=X(1);
base_y=Y(1);
axis square
viscircles(centers,radius);
for i= 1:5
base_x=X(i);
base_y=Y(i);
scatter( X, Y, 'f');
%D = digraph();
for j= 1:5
x1=[base_x;X(j)];
y1=[base_y;Y(j)];
hold on
distance = sqrt((base_x-x1).^2 + (base_y-y1).^2);
tableA(i,j,:)=[distance];
if distance <30
distance;
line(x1,y1);
hold on
hold on
distance =zeros(base_x, base_y);
paths = sparse(distance);
hold on
end
end
end
data=tableA(:,:,2);
for col = 1:5
for row = 1:5
data(col,row)
end
end

回答 (1 件)

Matt J
Matt J 2021 年 12 月 28 日

0 投票

The fact that your X,Y data came from a random number generator seems irrelevant. Once they have been generated, they define a graph just like any other data. You can find shortest paths through the graph using the shortestpath command.

カテゴリ

ヘルプ センター および File ExchangeGraph and Network Algorithms についてさらに検索

製品

タグ

質問済み:

2021 年 12 月 28 日

回答済み:

2021 年 12 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by