How to rename a vertices of agraphs

4 views (last 30 days)
Here is the code that I'm trying to rename graph nodes as a,b,c in output. But it shows error
a=[1 2 3];
b=[3 2 1];
g=graph(a,b);
p=plot(g);
c=[a b c];
p.NodeLabel=[c];

Accepted Answer

KSSV
KSSV on 23 Dec 2021
a=[1 2 3];
b=[3 2 1];
g=graph(a,b);
p=plot(g);
L={'a' 'b' 'c'};
p.NodeLabel=L;

More Answers (1)

Shanmugavelan S
Shanmugavelan S on 24 Dec 2021
Thank you sir. Suppose if we have n nodes, how to rename . This code works fine if vertex set is small. How to rename for a graph with n nodes(say)1:n as {2,4,6,... 2n} like that
  1 Comment
Steven Lord
Steven Lord on 24 Dec 2021
B = bucky;
g = graph(B(1:20, 1:20));
h = plot(g);
figure
h2 = plot(g);
h2.NodeLabel = string(2:2:40); % or
figure
h3 = plot(g);
h3.NodeLabel = "a" + (1:20);

Sign in to comment.

Categories

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

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!