MATLAB: Assign Numerical Node Labels

graph theorynode labeling

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.

Best Answer

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));