How to get the right edge order in a Digraph plot?

If I have the following code, I expect to have the rows aligned in the digraph (plot). However this example gives me a plot with some swapments. Labels and weights seems to align though. Does someone knows how to solve this?
f.e. expected: edge 17 from node 4 to node 6 with weigth 7.
plotted: edge 17 from node 6 to node 5?
N1=[3;2;4;5;6;6;4];
N2=[1;3;3;4;5;4;6];
weights=[1;2;3;4;5;6;7];
labels=[11;12;13;14;15;16;17];
N=digraph(N1,N2,weights);
figure(1)
plot(N,'linewidth',weights,'edgelabel',labels)

 Accepted Answer

Note that the edges in the digraph N are not necessarily stored in the same order in which you specified them when you created it.
You could create an edge table and use that to construct and plot the digraph.
E = table([N1, N2], weights, labels, 'VariableNames', ...
{'EndNodes', 'weights', 'labels'});
N2 = digraph(E);
plot(N2, 'linewidth', N2.Edges.weights, 'edgelabel', N2.Edges.labels)

More Answers (0)

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!