Create a digraph
object with three nodes and three edges. One edge is from node 1 to node 2, another is from node 1 to node 3, and the third is from node 2 to node 1.
G =
digraph with properties:
Edges: [3×1 table]
Nodes: [3×0 table]
View the edge table of the graph. For directed graphs, the first column indicates the source nodes of each edge, and the second column indicates the target nodes.
ans =
EndNodes
________
1 2
1 3
2 1
Add node names to the graph, then view the new node and edge tables. The source and target nodes of each edge are now expressed using their node names.
ans =
Name
____
'A'
'B'
'C'
ans =
EndNodes
__________
'A' 'B'
'A' 'C'
'B' 'A'
You can add or modify extra variables in the Nodes
and Edges
tables to describe attributes of the graph nodes or edges. However, you cannot directly change the number of nodes or edges in the graph by modifying these tables. Instead, use the addedge
, rmedge
, addnode
, or rmnode
functions to modify the number of nodes or edges in a graph.
For example, add an edge to the graph between nodes 2 and 3 and view the new edge list.
G =
digraph with properties:
Edges: [4×1 table]
Nodes: [3×1 table]
ans =
EndNodes
__________
'A' 'B'
'A' 'C'
'B' 'A'
'B' 'C'