www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/HighlightMinimumSpanningTreeOfGraphExample.m

    %% Highlight Minimum Spanning Tree of Graph
% Create and plot a graph. Return a handle to the |GraphPlot| object, |h|.

% Copyright 2015 The MathWorks, Inc.

s = [1 1 1 1 1 1 2 3 4 5 6 7 7 7 7 8 9 10 11 8 6];
t = [2 3 4 5 6 7 3 4 5 6 2 8 9 10 11 10 10 11 8 1 11];
G = graph(s,t);
h = plot(G)

%%
% Calculate the minimum spanning tree of the graph. Highlight the minimum
% spanning tree subgraph in the plot by increasing the line width and
% changing the color of the edges in the tree.
[T,p] = minspantree(G);
highlight(h,T,'EdgeColor','r','LineWidth',1.5)