MATLAB Answers

Changing the color of one particular node into different colors

13 ビュー (過去 30 日間)
Kashfia Mahin
Kashfia Mahin 2019 年 10 月 10 日
編集済み: Kashfia Mahin 2019 年 10 月 16 日
function pt = plot_topology_1(filename)
newfilename = [filename, '.network'];
fileID = fopen(newfilename);
if fileID == -1
error('Author:Function:OpenFile', 'Cannot open file: %s', newfilename);
C = textscan(fileID,'%c %d %d %f32 %f32 %f32 %f32 \n','Delimiter',',','HeaderLines',1);
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)
sup=supply_nodes(aa) %function of supply nodes
dem = demand_nodes(aa) %function of demand nodes
col= [0.3 8 12 5];
for i=1:d
if i==1
elseif i==2
elseif i==3
else i==4
p = plot(G)
highlight(p,sup, c ) % supply node color
highlight(p,dem,'NodeColor','g') %demand node color
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.

  0 件のコメント

Sign in to comment.


Steven Lord
Steven Lord 2019 年 10 月 10 日
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 件のコメント

表示 3 件の古いコメント
Kashfia Mahin
Kashfia Mahin 2019 年 10 月 15 日
Thank you so much. It works perfectly
Kashfia Mahin
Kashfia Mahin 2019 年 10 月 15 日
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 2019 年 10 月 15 日
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.

その他の回答 (0 件)

Translated by