How compute connected node with each main node
I need to compute the totl number of green nodes and red nodes connected with each main node as shown in figure below
the code is in below
%Composing fixed nodes t
for h=1:1:num_fixed_nodes
S1(h).xd = position_region(i,1) + fixed_nodes{i, 1}(h,1);
S1(h).yd = position_region(i,2) + fixed_nodes{i, 1}(h,2);
S1(h).distance = sqrt((S1(h).xd-bs_x)^2 + (S1(h).yd-bs_y)^2 );
S1(h).G=0;
S1(h).id=h;
S1(h).type=’C’;
S1(h).temp = interp2(aa1,bb1,temp_values_1,S1(h).xd,S1(h).yd);
S1(h).E = Eo*rand(1,1);
Et=Et+S1(h).E;
S1(h).node_status = S1(h).temp<thresh_temp;
if(S1(h).node_status==1)
scatter(S1(h).xd,S1(h).yd, ‘filled’,’MarkerFaceColor’,’m’);
else
scatter(S1(h).xd,S1(h).yd, ‘filled’,’MarkerFaceColor’,’r’);
end
end
%Composing random nodes that will then communicate with fixed
%nodes
for h=num_fixed_nodes+1:1:num_nodes
%Generate random nodes within the region
S1(h).xd = position_region(i,1) + rand(1,1)*region_width;
S1(h).yd = position_region(i,2) + rand(1,1)*region_height;
S1(h).G=0;
S1(h).id=h;
S1(h).type=’N’;
S1(h).temp = interp2(aa1,bb1,temp_values_1,S1(h).xd,S1(h).yd);
S1(h).E=Eo*rand(1,1);
Et=Et+S1(h).E;
S1(h).node_status = S1(h).temp<thresh_temp;
if(S1(h).node_status==1)
scatter(S1(h).xd,S1(h).yd, ‘filled’,’MarkerFaceColor’,’g’);
else
scatter(S1(h).xd,S1(h).yd, ‘filled’,’MarkerFaceColor’,’r’);
endI need to compute the totl number of green nodes and red nodes connected with each main node as shown in figure below
the code is in below
%Composing fixed nodes t
for h=1:1:num_fixed_nodes
S1(h).xd = position_region(i,1) + fixed_nodes{i, 1}(h,1);
S1(h).yd = position_region(i,2) + fixed_nodes{i, 1}(h,2);
S1(h).distance = sqrt((S1(h).xd-bs_x)^2 + (S1(h).yd-bs_y)^2 );
S1(h).G=0;
S1(h).id=h;
S1(h).type=’C’;
S1(h).temp = interp2(aa1,bb1,temp_values_1,S1(h).xd,S1(h).yd);
S1(h).E = Eo*rand(1,1);
Et=Et+S1(h).E;
S1(h).node_status = S1(h).temp<thresh_temp;
if(S1(h).node_status==1)
scatter(S1(h).xd,S1(h).yd, ‘filled’,’MarkerFaceColor’,’m’);
else
scatter(S1(h).xd,S1(h).yd, ‘filled’,’MarkerFaceColor’,’r’);
end
end
%Composing random nodes that will then communicate with fixed
%nodes
for h=num_fixed_nodes+1:1:num_nodes
%Generate random nodes within the region
S1(h).xd = position_region(i,1) + rand(1,1)*region_width;
S1(h).yd = position_region(i,2) + rand(1,1)*region_height;
S1(h).G=0;
S1(h).id=h;
S1(h).type=’N’;
S1(h).temp = interp2(aa1,bb1,temp_values_1,S1(h).xd,S1(h).yd);
S1(h).E=Eo*rand(1,1);
Et=Et+S1(h).E;
S1(h).node_status = S1(h).temp<thresh_temp;
if(S1(h).node_status==1)
scatter(S1(h).xd,S1(h).yd, ‘filled’,’MarkerFaceColor’,’g’);
else
scatter(S1(h).xd,S1(h).yd, ‘filled’,’MarkerFaceColor’,’r’);
end I need to compute the totl number of green nodes and red nodes connected with each main node as shown in figure below
the code is in below
%Composing fixed nodes t
for h=1:1:num_fixed_nodes
S1(h).xd = position_region(i,1) + fixed_nodes{i, 1}(h,1);
S1(h).yd = position_region(i,2) + fixed_nodes{i, 1}(h,2);
S1(h).distance = sqrt((S1(h).xd-bs_x)^2 + (S1(h).yd-bs_y)^2 );
S1(h).G=0;
S1(h).id=h;
S1(h).type=’C’;
S1(h).temp = interp2(aa1,bb1,temp_values_1,S1(h).xd,S1(h).yd);
S1(h).E = Eo*rand(1,1);
Et=Et+S1(h).E;
S1(h).node_status = S1(h).temp<thresh_temp;
if(S1(h).node_status==1)
scatter(S1(h).xd,S1(h).yd, ‘filled’,’MarkerFaceColor’,’m’);
else
scatter(S1(h).xd,S1(h).yd, ‘filled’,’MarkerFaceColor’,’r’);
end
end
%Composing random nodes that will then communicate with fixed
%nodes
for h=num_fixed_nodes+1:1:num_nodes
%Generate random nodes within the region
S1(h).xd = position_region(i,1) + rand(1,1)*region_width;
S1(h).yd = position_region(i,2) + rand(1,1)*region_height;
S1(h).G=0;
S1(h).id=h;
S1(h).type=’N’;
S1(h).temp = interp2(aa1,bb1,temp_values_1,S1(h).xd,S1(h).yd);
S1(h).E=Eo*rand(1,1);
Et=Et+S1(h).E;
S1(h).node_status = S1(h).temp<thresh_temp;
if(S1(h).node_status==1)
scatter(S1(h).xd,S1(h).yd, ‘filled’,’MarkerFaceColor’,’g’);
else
scatter(S1(h).xd,S1(h).yd, ‘filled’,’MarkerFaceColor’,’r’);
end plotting, sum MATLAB Answers — New Questions