Main Content

rmnode

Remove node from graph

Description

example

H= rmnode(G,nodeIDs)removes the nodes specified bynodeIDsfrom graphG. Any edges incident upon the nodes innodeIDsare also removed.rmnoderefreshes the numbering of the nodes inH, such that if you removed nodek, then nodes1:k-1have the same node numbers inH, and nodesk+1:numnodes(G)inGbecomek:numnodes(H)inH.

Examples

collapse all

Create and plot a graph.

s = [1 1 1 2 2 3]; t = [2 3 4 3 4 4]; G = graph(s,t); plot(G)

Figure contains an axes object. The axes object contains an object of type graphplot.

Remove node 1 from the graph and plot the result. The nodes in the new graph are automatically renumbered.

G = rmnode(G,1); plot(G)

Figure contains an axes object. The axes object contains an object of type graphplot.

Create and plot a graph with named nodes.

s = [1 1 1 1 2 2 3 3 3 5 5]; t = [2 3 4 6 1 5 4 5 6 4 6]; names = {'New York''Los Angeles''Washington D.C.''Pittsburgh'...'Denver''Austin'}; G = digraph(s,t,[],names); plot(G)

Figure contains an axes object. The axes object contains an object of type graphplot.

Remove the nodes'New York'and'Pittsburgh'from the graph, then replot the result.

G = rmnode(G,{'New York''Pittsburgh'}); plot(G,'Layout','force')

Figure contains an axes object. The axes object contains an object of type graphplot.

Input Arguments

collapse all

输入图,指定as either agraphordigraphobject. Usegraphto create an undirected graph ordigraphto create a directed graph.

Example:G = graph(1,2)

Example:G = digraph([1 2],[2 3])

Node identifiers, specified as one or more node indices or node names.

This table shows the different ways to refer to one or more nodes either by their numeric node indices or by their node names.

Form Single Node Multiple Nodes
Node index

Scalar

Example:1

Vector

Example:[1 2 3]

Node name

Character vector

Example:'A'

Cell array of character vectors

Example:{'A' 'B' 'C'}

String scalar

Example:"A"

String array

Example:["A" "B" "C"]

Example:G = rmnode(G,[1 2])removes node 1 and node 2 from graphG.

Output Arguments

collapse all

Output graph, returned as agraphordigraphobject.

Extended Capabilities

Version History

Introduced in R2015b