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
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 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!