1、求某两点间最短距离
利用matlab的bioinformatics Toolbox中的graphshortestpath
具体使用见MathWorks文档 http://cn.mathworks.com/help/bioinfo/ref/graphshortestpath.html?s_tid=srchtitle
以下给出一个简单的例子
A=[0 1 0 1 0;1 0 0 0 1;0 0 0 1 1;1 0 1 0 1;0 1 1 1 0] ;
A(isinf(A))=0;
[d,p,pred]=graphshortestpath(sparse(A),1,3); %结点1和3的最短距离
h=view(biograph(triu(sparse(A)),[],'ShowArrows','off','ShowWeights','off'));
2、求任意两点间最短距离矩阵
利用matlab的graphallshortestpaths
graphallshortestpaths(sparse(A));