flipedge

Reverses the direction of edges in a digraph.

Category: Mathematics > Graph and Network Algorithms

Syntax

H = flipedge(G)

Reverses every edge.

H = flipedge(G, idx)

Reverses only the edges listed in idx.

Description

An edge s -> t becomes t -> s. Reversing every edge gives the transpose graph, whose adjacency matrix is the transpose of the original; reachability questions of the kind "who can reach me" in G become "whom can I reach" in H.

For an undirected graph there is nothing to flip, so the function is meant for digraphs.

Input arguments

G
A digraph.
idx
Edge indices (positions in G.Edges).

Output arguments

H
A digraph with the same nodes and weights, and the chosen edges pointing the other way.

Example

Flip all or one edge

D = digraph([1 2], [2 3]);
F = flipedge(D);
disp(F.Edges.EndNodes)
E = flipedge(D, 1);
disp(E.Edges.EndNodes)
Output
     2     1
     3     2
     2     1
     2     3

See also

digraph predecessors successors adjacency