Assign Numerical Node Labels
5 次查看(过去 30 天)
显示 更早的评论
I am working with a digraph GG. I need to label the nodes in a different order than the order in which they appear in the adjacency matrix which was used to generate GG. I have these new integer-valued labels in a Nx1 vector called Name (N is the number of nodes). Why is it that I get an error when I use the following command?
>> GG.Nodes.Name = num2str(Name).
I also tried
>> labelnode(GG, 1:N, num2str(Name)),
again, to no avail.
Thank you very much for any advice you can offer.
采纳的回答
Christine Tobler
2020-7-2
For the first call, use
>> GG.Nodes.Name = num2str(Name)'
- GG.Nodes.Name has to be a column vector.
For the second call, labelnode only applies labels to a plot of a graph, not to the graph itself. For example
p = plot(GG);
labelnode(p, 1:26, num2str(Name));
But this is usually used to just relabel one or a few of the nodes. To set all of their labels in the plot (but not in the graph object), you would use
plot(GG, 'NodeLabel', num2str(Name));
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graph and Network Algorithms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!