graph-theory - 使用Matlab的dijkstra算法

标签 graph-theory matlab matlab-figure

我正在使用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/

相关文章:

matlab - 在直方图上绘制线条

Matlab - 用 surf 和 min 函数减去两个 3D 图形

python - 关于图形工具中嵌套 block 模型的基本问题

matlab - 对数 Matlab

matlab - 如何在matlab中合并两个不同维度的矩阵

Matlab将图形保存为特定大小?

matlab - 在第二台显示器上自动显示 matlab 图形

algorithm - 如何将一个连通的带权图划分为N个半等分子图

algorithm - 查找具有最小边交叉分区的图分区

neo4j - 如何使用Neo4J进行临时图计算?