Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Hello. I'm using the function ''shortestpath'' to solve a problem. However, I wish the output was a matrix with two columns, one the ''from'' nodes and the other the ''to'' nodes. Any ideas?

1 visualización (últimos 30 días)
%%using the shortestpath function on the example below, we have the following answer:
from = [1 2 3 3 5]; to = [2 3 4 5 6]; size = [16 4 4 6 4]; G = graph(from,to,size); [P,d] = shortestpath(G,1,6)
P = 1 2 3 5 6 d = 30 %%I wish the Path was like:
ans = [1 2; 2 3; 3 5; 5 6]
Thanks and best regards to all!

Respuestas (1)

Steven Lord
Steven Lord el 20 de Jul. de 2018
PM = P([1:end-1; 2:end].')

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by