degree of neighbor in wsn

1 visualización (últimos 30 días)
ali hadjer
ali hadjer el 8 de Nov. de 2015
Comentada: Preethi Priya el 17 de Feb. de 2020
i want to deploy a wsn in 100*100 axes with n node and R radius i calculat a distance between all the node and between a sink(100,100)position; 1-i want to calculte the nombre of neighbor (degree) for each node (i supose that distance(u,v)<R/2 to be neighbor(u,v)) 2- what i do :so i selection a node that dist(u,v)<R/2 and max degree(nombre of neighbor) and whos dist(sink,u) is minimale but he does not work : this is my code:
net = [1:n;rand([1,n])*x;rand([1,n])*y];
net1 = net;
*************%
degree=[];
if isfield(handles,'net')
for i = 1:numel(handles.net(1,:))
degree(i)=0;
for j = 1:numel(handles.net(1,:))
X1 = handles.net(2,i);
Y1 = handles.net(3,i);
X2 = handles.net(2,j);
Y2 = handles.net(3,j);
xSide = abs(X2-X1);
ySide = abs(Y2-Y1);
d = sqrt(xSide^2+ySide^2);% distance euclidienne
DD(:,i)=d;
%disp(DD);
%RESORTIR LES NOEUD REDONDANTS
if (d<(handles.r))&&(i~=j)
degree(i)=degree(i)+1;% CALCULE LEs nombre de neighbord( DEGRE) DES NOEUDS REDONDANTS
disp(degree(i))
if (max(degree))%&&(min(handles.d_sink))
plot([X1,X2],[Y1,Y2],'o','LineWidth',0.1);
grid on;
end
end
end
end

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 8 de Nov. de 2015
Ali - shouldn't DD be a square matrix since you are calculating the distance between every pair of nodes? So that
DD(i,j) = d;
Also, please clarify what you mean by but he does not work. Remember we don't have access to your data so we cannot run the above code. If you are observing an error, then please post them. Else describe exactly why you think the above is not doing what you expect.
Also, you state that ...distance(u,v)<R/2 to... yet in your code you are doing
if d<(handles.r)
Shouldn't this be
if d < (handles.r)/2
Finally, it is within the above block that you do the following
if (d<(handles.r))&&(i~=j)
degree(i)=degree(i)+1;% CALCULE LEs nombre de neighbord( DEGRE) DES NOEUDS REDONDANTS
disp(degree(i))
if (max(degree))%&&(min(handles.d_sink))
plot([X1,X2],[Y1,Y2],'o','LineWidth',0.1);
grid on;
end
end
Note that in the above, you may not have determined the degree for the ith node but only for some pairs up to j so checking to see if if there is a maximum now is premature. I would think that you would want to wait until you have calculated the degree for every node and then once that has been completed, find that node with the maximum degree and minimum distance to the sink.
  1 comentario
Geoff Hayes
Geoff Hayes el 8 de Nov. de 2015
ali's answer moved here
hello thank you so much mr Geoff Hayes so for ( if d<(handles.r)): i supose that the range of sensor (r)is equal to 2* R(range of communication) so i hant pb in that. :) but in the seconde part i have a pb: you have right to discribe my objectif: (would want to wait until you have calculated the degree for every node and then once that has been completed, find that node with the maximum degree and minimum distance to the sink.) + the condition of dist<d<(handles.r)

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by