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).
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)
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:1
Vector
Example:[1 2 3]
Node name
Character vector
Example:'A'
Cell array of character vectors
Example:{'A' 'B' 'C'}
String scalar
Example:"A"
String array
Example:["A" "B" "C"]
Node labels, specified as a character vector or a cell array of character
vectors.
If Labels is a character vector or string
scalar, then labelnode uses that label for each
node specified by nodeIDs.
If Labels is a cell array or string array, then
it must contain a label for each node specified by
nodeIDs.
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.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.