This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Label graph edges





labeledge(H,s,t,Labels) labels the edges specified by (s,t) pairs with the character vectors contained in Labels. The lengths of s, t, and Labels must be equal, or Labels can be scalar. If there are multiple edges between s and t, then the same label is applied to all of them.


labeledge(H,idx,Labels) specifies the edges to label using their edge indices. The edge indices are positive integers corresponding to the row number of the edge in the edge list of the graph, G.Edges.


collapse all

Create and plot a graph.

s = [1 1 1 2 2];
t = [2 3 4 2 5];
G = graph(s,t);
h = plot(G);

Label the edge weights using labeledge.

weights = [5 10 15 10 10];

Create and plot a graph.

s = [1 1 2 2 3];
t = [2 3 3 4 4];
G = graph(s,t);
h = plot(G);

Add text labels to three of the five graph edges.

labelText = {'ABC' 'DEF' 'GHI'};
labeledge(h,[1 1 2],[2 3 3],labelText)

Input Arguments

collapse all

Input graph plot, specified as a GraphPlot object. Use the graph or digraph functions to create a graph, and then use plot with an output argument to return a GraphPlot object.

Example: H = plot(G)

Edges to label, specified as separate arguments that indicate the end nodes of the edges as scalar node indices, vectors of node indices, character vector node names, or cell arrays of character vectors containing node names.

Example: labeledge(H,[1 2 2],[2 3 4],{'label1' 'label2' 'label3'})

Example: labeledge(H,{'a' 'b' 'b'},{'b' 'c' 'd'},{'label1' 'label2' 'label3'})

Edge indices, specified as scalar or vector of positive integers. The edge indices correspond to rows in the table H.Edges, such that H.Edges(idx,:) returns the end nodes of the edge. The maximum value for idx is numedges(H). The number of indices in idx must be the same as the number of values in Labels.

Example: labeledge(H,[1 3 5 7],{'label1' 'label2' 'label3' 'label4'})

Edge labels, specified as a character vector or a cell array of character vectors.

  • If Labels is a character vector, then labeledge uses that label for each specified edge.

  • If Labels is a cell array, then it must contain a label for each specified edge.

Data Types: char | cell

Introduced in R2015b

Was this topic helpful?