MATLAB: Degree of neighbor in wsn

degreeneighbor; selection

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

Best Answer

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.
Related Question