findedge

Index of the edge between two nodes.

Category: Mathematics > Graph and Network Algorithms

Syntax

idx = findedge(G, s, t)

Returns the position of the edge s-t in G.Edges.

Description

The index is the row of G.Edges that holds the edge, which lets you read or change its weight with G.Edges.Weight(idx). In an undirected graph findedge(G, s, t) and findedge(G, t, s) are equal. In a digraph the direction matters.

Input arguments

G
A graph or digraph.
s, t
End nodes of the edge, as indices or names.

Output arguments

idx
Edge index, or 0 when no such edge exists.

Example

Locate and read a weight

G = graph([1 2 3], [2 3 4], [10 20 30]);
k = findedge(G, 3, 2)
G.Edges.Weight(k)
findedge(G, 1, 4)
Output
k = 2
ans = 20
ans = 0

See also

findnode rmedge addedge edgecount