labelnode
Label graph nodes
Description
Examples
Label Graph Nodes
Create and plot a graph.
s = [1 1 2 2 3 4 5 5]; t = [2 3 3 4 4 5 1 2]; G = digraph(s,t); h = plot(G);
The plot
function automatically labels the graph nodes with their node indices (or with their node names, if available). Use text labels for some of the graph nodes instead.
labelnode(h,[1 2],{'source' 'target'})
Label node 3 and node 4 as 'A'
. Since the node labels do not change the underlying graph, G
, the labels can contain duplicate names (the official node names in G
must always be unique).
labelnode(h,[3 4],'A')
Input Arguments
nodeIDs
— Node identifiers
logical vector | node indices | node names
Node identifiers, specified as a logical vector or as one or more node
indices or node names. If nodeIDs
is a logical vector,
then its length must match the number of nodes 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: |
Labels
— Node labels
character vector | string scalar | cell array of character vectors | string array
Node labels, specified as a character vector or a cell array of character vectors.
If
Labels
is a character vector or string scalar, thenlabelnode
uses that label for each node specified bynodeIDs
.If
Labels
is a cell array or string array, then it must contain a label for each node specified bynodeIDs
.
Data Types: char
| cell
| string
Version History
Introduced in R2015b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)