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

7 visualizzazioni (ultimi 30 giorni)
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).

Risposta accettata

Geoff Hayes
Geoff Hayes il 14 Ott 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 Commenti
Geoff Hayes
Geoff Hayes il 30 Ott 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 il 30 Ott 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...

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by