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

Réponses (1)

Matt J
Matt J le 28 Déc 2021
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.

Catégories

En savoir plus sur Graph and Network Algorithms dans Centre d'aide et File Exchange

Produits

Question posée :

le 28 Déc 2021

Réponse apportée :

le 28 Déc 2021

Community Treasure Hunt

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

Start Hunting!

Translated by