Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

cannot understand how my approach should be on graph node coloring

1 vue (au cours des 30 derniers jours)
Sat m
Sat m le 11 Mai 2013
Clôturé : MATLAB Answer Bot le 20 Août 2021
i have a graph and i am able to input points in it. i am getting values of my graph nodes. i have choice so that user can choice which node to select first, which color to select for selected node and adjacent nodes. now what i want is, when an user will click node 1, and click on color red, then the node 1 in my graph will have red color and the adjacent node of node 1 will have different color. no adjacent sides can have the same color. and how do i define 2 adjacent nodes? thanx in advance . this is my code
DETAILS OF PROGRAMMING
% storing the nodes and color of nodes
img = imread('G.bmp');
image(img);
[x,y] = ginput(7)
v1 = [x(1),y(1)]
v2 = [x(2),y(2)]
v3 = [x(3),y(3)]
v4 = [x(4),y(4)]
v5 = [x(5),y(5)]
v6 = [x(6),y(6)]
v7 = [x(7),y(7)]
%%informed operator
% adjacent(v1) = [v2];
% adjacent(v2) = [v1,v3,v6,v7];
% adjacent(v3) = [v2,v4,v5];
% adjacent(v4) = [v3,v6];
% adjacent(v5) = [v3,v6];
% adjacent(v6) = [v2,v4,v5,v7];
% adjacent(v7) = [v2,v6];
% uicontrol('Style', 'text',...
% 'String', 'red',... %replace something with the text you want
% 'Units','normalized',...
% 'Position', [x(1) y(1) 0.1 0.1]);
%%giving user the choice to choose any node at first
prompt2 = 'which node you wish to go at first? ';
choice2 = menu('nodes in graph', 'v1', 'v2', 'v3', 'v4', 'v5', 'v6', 'v7')
node_num = choice2
%%selecting the color for the first node that is choosen
prompt = 'what color do you wish to put to this node? ';
choice = menu('colors available', 'red', 'blue', 'cyan', 'green')
color1 = choice
switch color1
case 1
disp('red')
case 2
disp('blue')
case 3
disp('cyan')
case 4
disp('green')
end
%%selecting the color for adjacent nodes of the selected node
prompt1 = 'what color do you wish to put to adjacent node? ';
choice1 = menu('colors available', 'red', 'blue', 'cyan', 'green')
color2 = choice1
switch color2
case 1
disp('red')
case 2
disp('blue')
case 3
disp('cyan')
case 4
disp('green')
end
switch node_num
case 1
disp('v1 is color 1, adj(v1) will be color 2')
case 2
disp('v2 is color 1, adj(v2) will be color 2')
case 3
disp('v3 is color 1, adj(v3) will be color 2')
case 4
disp('v4 is color 1, adj(v4) will be color 2')
case 5
disp('v5 is color 1, adj(v5) will be color 2')
case 6
disp('v6 is color 1, adj(v6) will be color 2')
case 7
disp('v7 is color 1, adj(v7) will be color 2')
end
if v1 == color1
v2 == color2
end
if v2 == color1
for i = 1:7
for j = 1:4
for k = 1:4
if node_num == i
color1 == j
color2 == k
v(i) = color(j)
adjacent(v(i)) = color(k)
end
end
end
end
end

Réponses (0)

Cette question est clôturée.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by