MATLAB: How to get and residual energy for cluster head and cluster member

clusterleachmatlab guisepteenwsn

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).

Best Answer

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