我正在使用 Matlab 做 dijkstra 算法。这是我的代码
W = [10 8 5 3 7 2 4 6 21];
DG = sparse([1 1 1 2 2 3 4 5 6],[2 4 3 4 5 6 6 6 1],W)
h = view(biograph(DG,[],'ShowWeights','on'))
[dist,path,pred] = graphshortestpath(DG,1,6)
set(h.Nodes(path),'Color',[1 0.4 0.4])
edges = getedgesbynodeid(h,get(h.Nodes(path),'ID'));
set(edges,'LineColor',[1 0 0])
set(edges,'LineWidth',1.5)
问题是我如何获得最短路径“重置”的红色线条节点和边缘。例如我希望它是,[dist,path,pred] = graphshortestpath(DG,2,3)
但图表仍然显示
[dist,path,pred] = graphshortestpath(DG,1,6).