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

    %% Minimum Spanning Tree of Cube Graph
% Create and plot a cube graph with weighted edges.

% Copyright 2015 The MathWorks, Inc.

s = [1 1 1 2 5 3 6 4 7 8 8 8];
t = [2 3 4 5 3 6 4 7 2 6 7 5];
weights = [100 10 10 10 10 20 10 30 50 10 70 10];
G = graph(s,t,weights);
p = plot(G,'EdgeLabel',G.Edges.Weight);

%%
% Calculate and plot the minimum spanning tree of the graph on top of the
% graph. |T| contains the same nodes as |G|, but a subset of the edges.
[T,pred] = minspantree(G);
highlight(p,T)