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

    %% Reorder Graph Nodes by Degree
% Create and plot a weighted graph.

% Copyright 2015 The MathWorks, Inc.

s = [1 1 1 2 2 2 2 3 4];
t = [3 4 2 3 4 5 6 5 6];
weights = [6 7 6 3 2 8 7 1 1]; 
G = digraph(s,t,weights);
plot(G,'EdgeLabel',G.Edges.Weight)

%%
% Reorder the graph nodes based on the out-degree, such that node 1 has the
% largest out-degree.
[~,order] = sort(outdegree(G),'descend')

%%
%
[H,idx] = reordernodes(G,order);
plot(H,'EdgeLabel',H.Edges.Weight)

%%
% |idx| describes the permutation of the rows in |G.Edges|. Confirm this
% correspondence using the |Weight| variable.
isequal(H.Edges.Weight, G.Edges.Weight(idx))