H = rmedge(G,s,t)
removes the edges specified by the node pairs s and
t from graph G. If there are multiple
edges specified by s and t, then they are all
removed.
This example shows how to remove all of the self-loops from a graph. Self-loops are edges that connect a node to itself.
Create a graph that has two self-loops.
G = graph([1 1 1 2],[1 2 3 2]);
plot(G)
Use rmedge to remove all self-loops from the graph. Even though G has only two self-loops, this technique removes all self-loops from any directed or undirected graph.
G = rmedge(G, 1:numnodes(G), 1:numnodes(G));
plot(G)
Input graph, specified as either a graph or digraph
object. Use graph to create an undirected graph or
digraph to create a directed graph.
Example: G = graph(1,2)
Example: G = digraph([1 2],[2 3])
Node pairs, specified as separate arguments of node indices or node names.
Similarly located elements in s and t
specify the source and target nodes for edges in the graph.
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 = rmedge(G,1,2) removes the edge between node
1 and node 2 from graph G.
Example: G = rmedge(G,{'a' 'b'},{'d' 'c'}) removes two
edges from graph G, the first of which is between node
'a' and node 'd'.
Edge indices, specified as a scalar or vector. The edge indices are
nonnegative integers that are row numbers in the G.Edges
table.
Example: G = rmedge(G,[1 3 5]) removes the first, third,
and fifth edges (rows) from G.Edges.
The node pairs s and t must be
node indices of the input graph G. Node names are not
supported.
When you construct a graph or
digraph object in MATLAB® and pass it to a MEX function generated using MATLAB
Coder™, you cannot remove edges from the graph object.
Thread-Based Environment Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window.
Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.