edgecount

Number of edges between two nodes of a multigraph.

Category: Mathematics > Graph and Network Algorithms

Syntax

n = edgecount(G, s, t)

Counts the edges between node s and node t.

Description

In a simple graph the answer is 0 or 1. Repeated pairs in the edge list create parallel edges, so the count can be larger, and ismultigraph reports true. In an undirected graph the order of s and t does not matter; in a digraph only edges from s to t are counted.

Input arguments

G
A graph or digraph, possibly with parallel edges.
s, t
A pair of nodes, as indices or names.

Output arguments

n
Number of edges joining the pair. 0 if they are not adjacent.

Example

Parallel edges

G = graph([1 1 2], [2 2 3]);
edgecount(G, 1, 2)
edgecount(G, 2, 3)
edgecount(G, 1, 3)
ismultigraph(G)
Output
ans = 2
ans = 1
ans = 0
ans = logical
   1

Notes

MatLivre handles one pair of nodes per call. MATLAB also accepts vectors of node pairs.

See also

ismultigraph numedges simplify findedge