필터 지우기
필터 지우기

Finding shortest path on random node distributed.

조회 수: 2 (최근 30일)
Asyran Abdullah
Asyran Abdullah 2018년 8월 11일
답변: Walter Roberson 2018년 8월 11일
Hi all, I have a problem to finding a shortest path in a random node distributed. Here is my code:
% code
rand('seed',123456);
x=randi([10, 100]);
y=randi([10, 100]);
G = digraph(max(randi([-60 10], 10), 0));
plot(G,'EdgeLabel',G.Edges.Weight)
title('Finding Shortest Path on Random Node');
I try to use a function of "shortestpath" but unfortunately it need a static node for source & destination. Hope other user can help me.
Thanks.

채택된 답변

Walter Roberson
Walter Roberson 2018년 8월 11일
[~, idx] = min(G.Edges.Weight);
shortest_path = G.Edges.EndNodes(idx,:);
Because you do not have a static node for source and destination, we are free to say that the shortest path is the single edge of minimum weight -- you have not, for example, said that the shortest path must be (say) length 3.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Construction에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by