Changing the color of one particular node into different colors

7 views (last 30 days)
function pt = plot_topology_1(filename)
newfilename = [filename, '.network'];
fileID = fopen(newfilename);
if fileID == -1
error('Author:Function:OpenFile', 'Cannot open file: %s', newfilename);
end
C = textscan(fileID,'%c %d %d %f32 %f32 %f32 %f32 \n','Delimiter',',','HeaderLines',1);
fclose(fileID);
no_of_edges = length(C{1})
final = no_of_edges;
a = C{2};
b = C{3};
edgewidth = C{5};
weights = randi([1 40],1, final);
G = graph(a,b,weights)
aa=incidence(G)
sup=supply_nodes(aa) %function of supply nodes
dem = demand_nodes(aa) %function of demand nodes
col= [0.3 8 12 5];
d=length(col)
i=0;
for i=1:d
if i==1
c='r';
elseif i==2
c='g';
elseif i==3
c='b';
else i==4
c='m';
end
p = plot(G)
highlight(p,sup, c ) % supply node color
highlight(p,dem,'NodeColor','g') %demand node color
end
end
there is only one supply node in this network and is indicated by red color. I want change the supply node color step by step in four diffrerent colors following the some given values. I made an array of 1*4 for four different color. But it shows that Matlab doesn't support the function. Please help me to figure it out.

Accepted Answer

Steven Lord
Steven Lord on 10 Oct 2019
What is the full and exact text of the error message you receive when you run that code? Include all the text displayed in red, exactly as it's shown in the Command Window. Don't paraphrase or summarize.
You also haven't shown us the functions supply_nodes and demand_nodes.
Finally, you probably don't want to plot the graph multiple times, once per element in your col vector. plot it once then highlight it multiple times (or highlight it with a vector of node IDs to change all those nodes at once.)
  6 Comments
Kashfia Mahin
Kashfia Mahin on 15 Oct 2019
Edited: Kashfia Mahin on 16 Oct 2019
Error using digraph/subsasgn (line 51)
To assign to or create a variable in a table, the number of rows must match the height of the table.
Error in plot_topology_mahin (line 32)
G.Nodes.value = randi([1 12],1,N); %Nodes value of all the nodes available in the network
Now I read the no of nodes from a network. i used randi function to generate Node value for the Node Colors following the number of nodes. There is a error showing which I don't figure it out how to solve.
Steven Lord
Steven Lord on 15 Oct 2019
This is close to a new issue, but it's easy to solve so I'll just respond here. If you encounter more problems that aren't directly related to the node coloring you may want to post a new question (perhaps linking back here for background material.)
N = 12;
t = table((1:N).')
r = randi([1 12], 1, N)
s = randi([1 12], N, 1)
What is the height of the table t?
What is the number of rows in r?
What is the number of rows in s?
You could use s to add a new variable to t, but you cannot use r to add a new variable to t. s and r have the same number of elements but not the same number of rows and that makes a big difference.
t.newvar1 = s % Works
t.newvar2 = r % Does not work

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!