1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| clc,clear
a = zeros(6);
a(1,[2 3])=[14 18]; a(2,[3:5])=[13 18 16]; a(3,[4 5])=[12 16]; a(4,[5 6])=[14 19]; a(5,6)=10;
s=cellstr(strcat('城市',int2str([1:6]'))); G=graph(a,s,'upper'); p=plot(G,'EdgeLabel',G.Edges.Weight);
T=minspantree(G,'Method','sparse');
L = sum(T.Edges.Weight) highlight(p,T,"EdgeColor","red",'LineWidth',2.5)
|