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

4 Ansichten (letzte 30 Tage)
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).

Akzeptierte Antwort

Geoff Hayes
Geoff Hayes am 14 Okt. 2014
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 Kommentare
Geoff Hayes
Geoff Hayes am 30 Okt. 2014
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 am 30 Okt. 2014
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...

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by