Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

findedge

Locate edge in graph

Syntax

idxOut = findedge(G,s,t)
[sOut,tOut] = findedge(G)
[sOut,tOut] = findedge(G,idx)

Description

example

idxOut = findedge(G,s,t) returns the numeric edge indices, idxOut, for the edges specified by the source and target node pairs s and t. The edge indices correspond to the rows G.Edges.Edge(idxOut,:) in the G.Edges table of the graph. An edge index of 0 indicates an edge that is not in the graph.

example

[sOut,tOut] = findedge(G) returns the source and target node IDs, sOut and tOut, for all of the edges in graph G.

example

[sOut,tOut] = findedge(G,idx) finds the source and target nodes of the edges specified by idx.

Examples

collapse all

Create a graph, and then determine the edge index for the (1,2) and (3,5) edges.

s = [1 1 2 2 2 3 3 3];
t = [2 3 3 4 5 6 7 5];
G = graph(s,t)
G = 
  graph with properties:

    Edges: [8x1 table]
    Nodes: [7x0 table]

idxOut = findedge(G,[1 3],[2 5])
idxOut = 

     1
     6

idxOut contains the row index into G.Edges.EndNodes for each specified edge.

Create a graph, and then determine the end nodes of all edges in the graph.

s = {'a' 'a' 'b' 'b' 'c' 'c'};
t = {'b' 'c' 'd' 'e' 'f' 'g'};
G = graph(s,t)
G = 
  graph with properties:

    Edges: [6x1 table]
    Nodes: [7x1 table]

[sOut,tOut] = findedge(G)
sOut = 

     1
     1
     2
     2
     3
     3

tOut = 

     2
     3
     4
     5
     6
     7

Create a graph, and then determine the end nodes for the edges whose indices are 3 and 7.

s = [1 1 1 1 2 2 3 3 4 4];
t = [2 3 4 5 6 7 8 9 10 11];
G = digraph(s,t)
G = 
  digraph with properties:

    Edges: [10x1 table]
    Nodes: [11x0 table]

[sOut,tOut] = findedge(G,[3 7])
sOut = 

     1
     3

tOut = 

     4
     8

Create a graph.

s = [1 1 2 3];
t = [2 3 3 4];
weights = [10 20 30 40];
G = graph(s,t,weights)
G = 
  graph with properties:

    Edges: [4x2 table]
    Nodes: [4x0 table]

Find the weight of the (1,3) edge, using findedge to retrieve the index.

G.Edges.Weight(findedge(G,1,3))
ans = 20

Input Arguments

collapse all

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 scalars, vectors, character vectors, or cell arrays of character vectors. Similarly located elements in s and t specify the source and target nodes that form edges in the graph.

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

Example: G = findedge(G,{'a' 'a'; 'b' 'c'},{'b' 'c'; 'c' 'e'})

Edge indices, specified as a scalar or vector of positive integers. The edge index corresponds to a row in the G.Edges table of the graph, G.Edges(idx,:).

Output Arguments

collapse all

Edge indices, returned as a scalar or vector of nonnegative integers. The edge indices correspond to rows in the G.Edges table of the graph, G.Edges(idxOut,:). An edge index of 0 indicates an edge that is not in the graph.

Node IDs, returned as separate scalars or vectors of positive integers. Similarly located elements in sOut and tOut specify the source and target nodes that form the edges G.Edges(idx,:).

Introduced in R2015b

Was this topic helpful?