www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/SubsetOfShortestPathsWithSpecifiedSourceNodeExample.m
%% Subset of Shortest Paths with Specified Source Node % Find the shortest paths and path lengths from a single source node to % several target nodes. % % Create and plot a graph. % Copyright 2015 The MathWorks, Inc. G = digraph(bucky); plot(G) %% % Find the shortest paths from node 23 to several other nodes. Specify % |OutputForm| as |cell| to return the shortest paths in a cell array. % Specify two outputs to also return the shortest path distances. target = [1 5 13 32 44]; [tree,D] = shortestpathtree(G,23,target,'OutputForm','cell') %% % |tree{j}| is the shortest path from node 23 to node |target(j)| with % length |D(j)|. % % Find the path and path length from node 21 to node 5. path = tree{2} %% % path_length = D(2)