Note: This page has been translated by MathWorks. Please click here

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Graph with directed edges

`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)

`G = digraph`

`G = digraph(A)`

`G = digraph(A,nodenames)`

`G = digraph(A,NodeTable)`

`G = digraph(A,___,'OmitSelfLoops')`

`G = digraph(s,t)`

`G = digraph(s,t,weights)`

`G = digraph(s,t,weights,nodenames)`

`G = digraph(s,t,weights,NodeTable)`

`G = digraph(s,t,weights,num)`

`G = digraph(s,t,___,'OmitSelfLoops')`

`G = digraph(s,t,EdgeTable,___)`

`G = digraph(EdgeTable)`

`G = digraph(EdgeTable,NodeTable)`

`G = digraph(EdgeTable,___,'OmitSelfLoops')`

creates an empty
directed graph object, `G`

= digraph`G`

, which has no nodes or
edges.

creates a weighted directed graph using a square adjacency matrix,
`G`

= digraph(`A`

)`A`

. 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, if ```
A(2,1)
= 10
```

, then `G`

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 be numeric, character vectors, or cell arrays
of character vectors with the same number of elements.

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`

.

Access and Modify Nodes and Edges

`addedge` | Add new edge to graph |

`rmedge` | Remove edge from graph |

`flipedge` | Reverse edge directions |

`addnode` | Add new node to graph |

`rmnode` | Remove node from graph |

`findedge` | Locate edge in graph |

`findnode` | Locate node in graph |

`numedges` | Number of edges in graph |

`numnodes` | Number of nodes in graph |

`reordernodes` | Reorder graph nodes |

`subgraph` | Extract subgraph |

Search and Structure

`bfsearch` | Breadth-first graph search |

`dfsearch` | Depth-first graph search |

`centrality` | Measure node importance |

`toposort` | Topological order of directed acyclic graph |

`transclosure` | Transitive closure |

`transreduction` | Transitive reduction |

`isdag` | Determine if graph is acyclic |

`conncomp` | Connected graph components |

`condensation` | Graph condensation |

`maxflow` | Maximum flow in graph |

`isisomorphic` | Determine whether two graphs are isomorphic |

`isomorphism` | Compute equivalence relation between two graphs |

Shortest Path

`shortestpath` | Shortest path between two single nodes |

`shortestpathtree` | Shortest path tree from node |

`distances` | Shortest path distances of all node pairs |

Node Information

`indegree` | In-degree of nodes |

`outdegree` | Out-degree of nodes |

`predecessors` | Node predecessors |

`successors` | Node successors |

`nearest` | Nearest neighbors within radius |

Visualization

`plot` | Plot graph nodes and edges |

Was this topic helpful?