reordernodes
Reorder graph nodes
Description
Examples
Reorder Graph Nodes
Create and plot a graph.
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]; G = graph(s,t); plot(G)
Reorder the graph nodes using a permutation vector.
order = [7 2 3 4 8 1 5 6]; G = reordernodes(G,order); plot(G)
Reorder Graph Nodes by Degree
Create and plot a weighted graph.
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')
order = 6×1
2
1
3
4
5
6
[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))
ans = logical
1
Input Arguments
order
— Node order
node indices | node names
Node order, specified as node indices or node names.
order
specifies a symmetric permutation of the
adjacency matrix of G
. If A =
adjacency(G)
, then A(order,order)
produces
adjacency(H)
.
order
can be one of:
Numeric vector of node indices, such as
[1 3 2]
.A cell array of character vectors or string array of node names, such as
{'A' 'C' 'B'}
or["A" "C" "B"]
.
Example: H = reordernodes(G,[3 1 2])
Output Arguments
H
— Output graph
graph
object | digraph
object
Output graph, returned as a graph
or
digraph
object. H
contains the
same Nodes
and Edges
properties as
G
, but with the rows of H.Nodes
and H.Edges
permuted:
H.Nodes
is the same asG.Nodes(order,:)
.H.Edges
is similar toG.Edges(idx,:)
, except that the nodes are renumbered.
idx
— Permutation vector of edge indices
vector
Permutation vector of edge indices, returned as a vector. The values in
idx
describe the permutation of the rows in
G.Edges
.
Extended Capabilities
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
Version History
Introduced in R2015b
Abrir ejemplo
Tiene una versión modificada de este ejemplo. ¿Desea abrir este ejemplo con sus modificaciones?
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)