labeledge
Label graph edges
Description
Examples
Label Graph Edge Weight
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]; labeledge(h,1:numedges(G),weights)
Add Text Labels to Graph Edges
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
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: labeledge(H,[1 2 2],[2 3 4],{'label1' 'label2'
'label3'})
Example: labeledge(H,{'a' 'b' 'b'},{'b' 'c' 'd'},{'label1'
'label2' 'label3'})
idx
— Edge indices
scalar | vector
Edge indices, specified as a scalar, vector of positive integers, or logical vector.
A vector of positive integers specifies edge indices for a graph
G
corresponding to rows in the tableG.Edges
, such thatG.Edges(idx,:)
returns the end nodes of the edge. In this form, the maximum value foridx
isnumedges(G)
, and the number of selected nodes is equal to the number of indices inidx
.A logical vector specifies whether each edge is labeled. In this form, the length of the logical vector must be
numedges(G)
, and the number of selected nodes is equal to the number of nonzero indices inidx
.
Example: labeledge(H,[1 3 5 7],{'label1' 'label2' 'label3'
'label4'})
Labels
— Edge labels
character vector | string scalar | cell array of character vectors | string array
Edge labels, specified as a character vector, string scalar, cell array of character vectors, or string array.
If
Labels
is a character vector or string scalar, thenlabeledge
uses that label for each specified edge.If
Labels
is a cell array or string array, then it must contain a label for each specified edge.
Data Types: char
| cell
| string
Version History
Introduced in R2015b
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
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)