rmedge
Remove edge from graph
Description
Examples
Remove Edges with Specified End Nodes
Create and plot a graph.
s = [1 1 1 2 2 3 3 4 5 5 6 7]; t = [2 4 5 3 6 4 7 8 6 8 7 8]; G = graph(s,t); plot(G)
Remove several edges from the graph and plot the result.
G = rmedge(G,[1 2 3 4],[5 6 7 8]); plot(G)
Remove Edge with Specified Index
Create a graph and view the edge list.
s = {'BOS' 'NYC' 'NYC' 'NYC' 'LAX'}; t = {'NYC' 'LAX' 'DEN' 'LAS' 'DCA'}; G = digraph(s,t); G.Edges
ans=5×1 table
EndNodes
__________________
{'BOS'} {'NYC'}
{'NYC'} {'LAX'}
{'NYC'} {'DEN'}
{'NYC'} {'LAS'}
{'LAX'} {'DCA'}
Remove the edge between nodes 'NYC'
and 'DEN'
using the edge index.
G = rmedge(G,3); G.Edges
ans=4×1 table
EndNodes
__________________
{'BOS'} {'NYC'}
{'NYC'} {'LAX'}
{'NYC'} {'LAS'}
{'LAX'} {'DCA'}
Remove Self-Loops
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 Arguments
s,t
— Node pairs (as separate arguments)
node indices | node names
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: | Vector Example: |
Node name | Character vector Example: | Cell array of character vectors Example: |
String scalar Example: | String array Example: |
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'
.
idx
— Edge indices
scalar | vector
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
.
Output Arguments
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
The node pairs
s
andt
must be node indices of the input graphG
. Node names are not supported.When you construct a
graph
ordigraph
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
.
Version History
Introduced in R2015b
MATLAB Command
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.
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)