我正在使用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).
最佳答案
这样做:
set(h.edges, 'LineColor', [0.5 0.5 0.5])
set(h.edges, 'LineWidth', 0.5)
set(h.nodes, 'Color', [1 1 0.7])
您只需执行
get(h)
即可检查您可以更改的所有其他属性。关于设置传记对象的属性,还有一些不错的在线信息:
http://www.mathworks.com/help/toolbox/bioinfo/ref/setbiograph.html
关于graph-theory - 使用Matlab的dijkstra算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8075875/