How to get and residual energy for cluster head and cluster member ?

조회 수: 1 (최근 30일)
Matlab111
Matlab111 2014년 10월 14일
댓글: Matlab111 2014년 10월 30일
http://www.mathworks.in/matlabcentral/answers/153186#comment_235285 sir from your code i can get an cluster head and cluster head members. But i want to get their residual energy also ('energy'(S.E in my code)).For every node i want.(i need both cluster head and cluster member energy).

채택된 답변

Geoff Hayes
Geoff Hayes 2014년 10월 14일
Arul - why not just add a third column to the clusterHeads and clusterNodes matrices. From the link you provided, just modify the code to something like the following
clusterData = cell(size(X,2),1);
for k=1:size(clusterData)
clusterData{k}.clusterHead = [X(k) Y(k) E(k)];
clusterData{k}.clusterNodes = [];
end
for k=1:size(S,2)
x = S(k).xd;
y = S(k).yd;
energy = S(k).ENERGY;
minDist = Inf;
at = 0;
for u=1:size(X,2)
dist = sqrt((x-X(u))^2+(y-Y(u))^2);
if dist<minDist
minDist = dist;
at = u;
end
end
if at>0
clusterData{at}.clusterNodes = ...
[clusterData{at}.clusterNodes ; [x y energy] ];
end
end
Note that the above is untested, and assumes that you have created an E energy array in the manner that you created the X and Y arrays i.e.
X(cluster)=S(i).xd;
Y(cluster)=S(i).yd;
E(cluster)=S(i).ENERGY; % <-- add this line
  댓글 수: 22
Geoff Hayes
Geoff Hayes 2014년 10월 30일
As your question has been answered, any further questions relating to the code you have taken from the File Exchange should be directed to the author.
Matlab111
Matlab111 2014년 10월 30일
k sir thank you , but according to author which ever has the higher residual energy that's going to be the cluster head and even in basic LEACH algorithm also saying the same thing. so please sir try this one please.
Don't ignore this code please tell the mistake in my code please...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 WSNs에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by