digraph
Graph with directed edges
Description
digraph
objects represent directed graphs, which have
directional edges connecting the nodes. After you create a digraph
object, you can learn more about the graph by using the object functions to perform
queries against the object. For example, you can add or remove nodes or edges, determine
the shortest path between two nodes, or locate a specific node or edge.
G = digraph([1 1], [2 3]) e = G.Edges G = addedge(G,2,3) G = addnode(G,4) plot(G)
Creation
Syntax
Description
creates an empty
directed graph object, G
= digraphG
, which has no nodes or
edges.
creates a directed graph using a square adjacency matrix,
G
= digraph(A
)A
.
For logical adjacency matrices, the graph has no edge weights.
For nonlogical adjacency matrices, the graph has edge weights. The location of each nonzero entry in
A
specifies an edge for the graph, and the weight of the edge is equal to the value of the entry. For example, ifA(2,1) = 10
, thenG
contains an edge from node 2 to node 1 with a weight of 10.
specifies directed graph edges G
= digraph(s,t
)(s,t)
in pairs to
represent the source and target nodes. s
and
t
can specify node indices or node names.
digraph
sorts the edges in G
first by source node, and then by target node. If you have edge properties
that are in the same order as s
and t
,
use the syntax G = digraph(s,t,EdgeTable)
to pass in the
edge properties so that they are sorted in the same manner in the resulting
graph.
does not add any self-loops to the graph. That is, any G
= digraph(s,t
,___,'omitselfloops')k
that satisfies s(k) == t(k)
is ignored. You can use any
of the input argument combinations in previous syntaxes.
uses the table G
= digraph(EdgeTable
)EdgeTable
to define the graph. With this
syntax, the first variable in EdgeTable
must be named
EndNodes
, and it must be a two-column array defining
the edge list of the graph.
does not add self-loops to the graph. That is, any G
= digraph(EdgeTable
,___,'omitselfloops')k
that
satisfies EdgeTable.EndNodes(k,1) ==
EdgeTable.EndNodes(k,2)
is ignored. You must specify
EdgeTable
and optionally can specify
NodeTable
.