MATLAB: How to convert graph to digraph

digraphedgegraphgraph theory

Hi all –
I plotted an graph and want to make some specific edges to be directed (digraph). Just to be a bit clearer: I have a full plotted and formatted minimum spanning tree from a graph which is not directed. I want to loop through the edges and, if a certain condition is met, replace the edge for a directed edge, pointing from node A to node B.
Is this possible? My graph would have both directed and undirected edges.
Best.

Best Answer

I'm afraid it's not possible to have both directed and undirected edges in the same graph. To convert a graph to a digraph, you could use
gDirected = digraph(adjacency(gUndirected));
This will replace every undirected edge with two directed edges going in opposing directions. You could then use rmedge to remove the edges that go in the direction you don't want.
Within most graph algorithms, these two edges will behave the same way as the undirected edge did - but of course, the plot will look very different.