2011-11-10 64 views
3

我正在做使用Matlab的dijkstra算法。这里是我的代码使用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). 

回答

1

这将做到这一点:

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)改变的其他属性。

还有有关设置的Biograph对象的属性一些良好的网上信息:

http://www.mathworks.com/help/toolbox/bioinfo/ref/setbiograph.html