a = [,,,,,,]; % 起点节点 b = [,,,,,,]; % 终点节点 c = [,,,,,,]; % 对应权值 g = digraph(a,b,c); % 创建图 [path,distance] = shortestpath(g,,); % 计算最短路 plot(g) %显示图,没必要显示可以不写 在Matlab中有可以计算最短路的函数,先用digraph生成加权图,再用shortestpath计算最短路.Matlab代码可以计算上面有向图中节点 1 到 5 的最短路,path是最