how i can solve this proble of degree!!!!!!!!!!!!!?????????????????,
1 view (last 30 days)
Show older comments
i want to count a nombre of neighbor of node (degree(i,j))but i obtained a float number(like 45.4288)and somtimes a nombre < of total of numbre (50 node and 103.2446 neighbor !!!!!! its impossible) pllllllz help me my code :
degree=[];
if isfield(handles,'net')
for i = 1:numel(handles.net(1,:))
for j = 1:numel(handles.net(1,:))
degree(i,j)=0;
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,j)=d %matrice de distance entre noeuds
%RESORTIR LES NOEUD REDONDANTS
if (DD(i,j)< 2*(handles.r))&&(i~=j)
degree(i,j)=degree(i,j)+1;% CALCULE LEs nombre de neighbord( DEGRE) DES NOEUDS REDONDANTS
disp(degree(i,j));
end;
end
end
0 Comments
Answers (1)
Geoff Hayes
on 9 Nov 2015
ali - your above code would never set a non-integer number as any element in the degree array since all you ever do is just increment any element by one. So I think that you have not provided the code that generates the error that you are observing.
One problem that I do see with your code is the use of degree. Why is it an nxn matrix where you consider each pair? Because that would mean that you would only ever have ones or zeros in this matrix. If you want to find the degree (number of neighbours) for each node, then if you have n nodes, your degree array would be nx1. And so your code would be as follows
if isfield(handles,'net')
n = numel(handles.net(1,:);
degrees = zeros(n,1);
for u=1:n
X1 = handles.net(2,u);
Y1 = handles.net(3,u);
for v=1:n
X2 = handles.net(2,v);
Y2 = handles.net(3,v);
xSide = abs(X2-X1);
ySide = abs(Y2-Y1);
d = sqrt(xSide^2+ySide^2);% distance euclidienne
DD(u,v)=d; %matrice de distance entre noeuds
%RESORTIR LES NOEUD REDONDANTS
if (DD(u,v)< 2*(handles.r))&&(u~=v)
degree(u)=degree(u)+1;
end;
end
end
end
3 Comments
See Also
Categories
Find more on Web Services in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!