A graph object is undirected. A digraph object is directed. Construct your network graph using digraph instead of graph on the fourth line of your code.
By the way, the addedge function has two capabilities you might find useful.
- The s (source) and t (target) inputs can be vectors to add multiple edges at once.
- If the source and/or target inputs reference nodes that don't yet exist, addedge adds them.
So you could do this with something like:
G = digraph(triu(ones(3)));
figure;
plot(G)
N = numnodes(G);
newnodes = [N+1 N+2];
G2 = addedge(G, [1 newnodes], [newnodes 2], pi);
G2 = rmedge(G2, 1, 2);
figure;
plot(G2)
Best Answer