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 Exchange에서 Graph 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