In below code to simulate a node on Wireless networks.
clc
clear all
close all
warning off
net_width = 10;
net_height = 80;
check = 1;
tot_nodes = 20;
traves_MS = 10;
hT = 4;
% Form Network area....
node_count = 1;
all_x = [];
all_y = [];
for j = 0:9:net_height
if check==1
start = 0;
check = 0;
else
start = 5;
check = 1;
end
for i = start:10.3:net_height
circle([j,i],6,7,'-');
hold on
drawnow
plot(j,i,j,i,'.','color','green');
nodes(node_count).x = j;
nodes(node_count).y = i;
nodes(node_count).id = node_count;
node_count = node_count+1;
all_x = [all_x;i];
all_y = [all_y;j];
end
end
axis square;
min_x = min(all_x);
max_x = max(all_x);
min_y = min(all_y);
max_y = max(all_y);
% Making Random nodes....
for i = 1:tot_nodes
x = round(min_x+(max_x-min_x)*rand);
y = round(min_y+(max_y-min_y)*rand);
pnt1 = [x y] ;
best_node_inx = best_dist(pnt1,nodes);
best_x = nodes(best_node_inx).x;
best_y = nodes(best_node_inx).y;
best_pnt = [best_x best_y];
plot(x,y,x,y,'*','color','red');
all_x = [pnt1(1) best_pnt(1)];
all_y = [pnt1(2) best_pnt(2)];
plot(all_x,all_y);
hold on
drawnow
end
% Making Moving Nodes...
s_min_x = min_x+0.5;
s_min_y = min_y+0.5;
con_x = 1;
check = 1;
totms = 0;
traverse_node = [];
station_count = [];
station_data = [];
sel_nodes = [];
last_check_pnt = 1;
while(totms~=traves_MS)
if s_min_x<=max_x&&check == 1
check = 1;
else
check = 0;
if s_min_x<=min_x && check == 0
check = 1;
end
end
if check ==1
s_min_x = s_min_x+1;
s_min_y = s_min_y+1;
else
s_min_x = s_min_x-1;
s_min_y = s_min_y-1;
end
h1 = plot(s_min_x,s_min_y,s_min_x,s_min_y,'*','color','red');
pnt1 = [s_min_x s_min_y] ;
best_node_inx = best_dist(pnt1,nodes);
best_x = nodes(best_node_inx).x;
best_y = nodes(best_node_inx).y;
best_pnt = [best_x best_y];
hold on
drawnow
all_x = [pnt1(1) best_pnt(1)];
all_y = [pnt1(2) best_pnt(2)];
h2 = plot(all_x,all_y);
pause(0.1);
delete(h1);
delete(h2);
end
Output
No comments:
Post a Comment