File Exchange

image thumbnail

Digraph Datatype with Vertex labels

version (29.8 KB) by Steve McClure
Compute/manipulate directed graph while retaining vertex labels


Updated 01 Sep 2016

View Version History

View License

While many algorithms have been written to compute/manipulate directed graphs (digraphs), few do so with associated vertex names or labels.
The problem I was interested in solving required to see “who depends on who” in a complex web of inter-dependencies. I needed to answer such questions as
- Does A depend on Z?
- Explicitly or implicitly?
- What is the chain of dependencies?
- Which dependencies are redundant?
- Are there any circular dependencies?
This class provides the convenience of an underlying structure to keep the vertices associated with the indices of the Adjacency Matrix, all with performance always in mind for graphs with thousands of vertices.
This also provides a fairly convenient opening to make use of GraphViz technologies ( to output a clean graph, but was left out of this class implementation due to the extreme customization allowed via GraphViz.
== UPDATE Aug2014 ==
I've replaced the 4 search functions getDirectForward, getDirectBackward, getAllForward, getAllBackward with one succinct and faster function "findall". In case you need to migrate code, the following are functionally equivalent:

getDirectForward(DG,V) -> findall(DG,V,1)
getDirectBackward(DG,V) -> findall(DG,V,-1)
getAllForward(DG,V) -> findall(DG,V,Inf)
getAllBackward(DG,V) -> findall(DG,V,-Inf)

Cite As

Steve McClure (2021). Digraph Datatype with Vertex labels (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (5)

Madhura Ghandi

Helped me with my task of path planning when I couldn't use the recent MATLAB versions. It would be great if there are some additional functions included to visualize the digraph.

Steve McClure

@QuangAnhTa, I had originally developed and published this functionality in Nov 2013, using the latest R2013b release at that point. This happened to pre-date a similar project within MathWorks (which I was not aware of then), delivered in R2015b:

We both happen to have a "digraph" object with very similar functionalities, but I have stopped updating this file exchange since learning about the official support for graphs. Were you looking for the set-functionalities like union, intersect, etc on the new native digraph objects?

Quang Anh Ta

Nice job. As you work for Mathwork, I would like to know why advanced fonctionnalities such that intersect, union, etc. are not submitted in a recent Matlab distribution (R2016a). Many thanks.

Ligong Han


Nice work. Clearly written help. Unit Tests are well considered (and all work).

Perhaps the model for a good submission to the file exchange...

MATLAB Release Compatibility
Created with R2013b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!