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

1 次查看(过去 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