rmnode

Removes nodes, and the edges at them, from a graph or digraph.

Category: Mathematics > Graph and Network Algorithms

Syntax

H = rmnode(G, nodeIDs)

Removes the listed nodes.

Description

Renumbering means node k of G may become a lower index in H; use node names to track nodes through removals. To keep a chosen set of nodes instead of dropping one, use subgraph.

Input arguments

G
A graph or digraph.
nodeIDs
Node indices or names.

Output arguments

H
The graph without those nodes. Edges touching a removed node disappear, and the remaining nodes are renumbered consecutively.

Example

Removing a hub

G = graph([1 2 3 3 4], [2 3 1 4 5]);
H = rmnode(G, 3);
numnodes(H)
disp(H.Edges.EndNodes)
Output
ans = 4
     1     2
     3     4

See also

addnode rmedge subgraph graph