How to use non-unique node names in a digraph?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Monika Jaskolka
le 1 Août 2020
Réponse apportée : Christine Tobler
le 3 Août 2020
I am trying to plot a Simulink model as a graph. I am using the digraph function, but I am running into issues because Simulink elements can have non-unique names. For example, a model can have any amount of subsystems named "Subsystem", so long as they are at different hierarchical levels. The same goes for Inports named "In1", Outports named "Out1", etc. And given that these are the default names for these elements, there typically are many elements with the same names.
A simple example of what I want to acheive is shown in the image. However, I receive an error saying node names must be unique. Is there a better way of plotting graphs with non-unique names displayed? I don't want to append suffixes to make the labels unique, because that would make the plot inaccurate.
s = [1 2 3];
t = [2 3 3];
w = ones(1, length(t));
n = {'Block Diagram', 'Subsystem', 'Subsystem'};
G = digraph(s, t, w, n, 'omitselfloops');
h = plot(G);
0 commentaires
Réponse acceptée
Christine Tobler
le 3 Août 2020
Instead of setting these inputs as node names, add them as a separate variable in the nodes table. Then, pass them to the plotting function as node labels:
G = digraph(s, t, w, [], 'omitselfloops');
G.Nodes.Label = n;
plot(G, 'NodeLabel', G.Nodes.Label);
The node names of a graph have to be unique because they can be used to specify a node as input to some functions (for example shortestpath). But this is not the case for the labels in the plot of a graph.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Graph and Network Algorithms dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!