I have used the following code to create a wsn virtual structure with 4*4 grid-cells and have deployed 100 nodes in it. Each cell is headed by a cluster-head which is in center of the cell i.e their are a total of 16 cluster-heads. Now , i have to make Area-headers which will be heading four 2*2 grid cells and are in the center of the 2*2 grid-cells , i.e their would be a total of 4 Area-headers. I am attaching the pic. to better explain the position of the Area-headers. how could that be done. Please help.
% WSN Grid structure with 4*4 cells made
NrGrid = 4; x = linspace(0, 100, NrGrid+1);[X,Y] = meshgrid(x);figure(1)plot(X,Y,'k')hold onplot(Y,X,'k')hold offset(gca, 'Box','off', 'XTick',[], 'YTick',[])axis square % grid formation ends
% Nodes deployment started
NrGrid = 4; coords = rand(100,2) * NrGrid + 1;scatter(coords(:,1),coords(:,2));set(gca, 'XTick', 1:NrGrid+1, 'YTick', 1:NrGrid+1)grid on % Nodes deployment ends
%All good upto here
%cluster head selection on basis of most near to the center
[XC, YC] = ndgrid(1/2:NrGrid+1/2, 1/2:NrGrid+1/2); center_idx = zeros(NrGrid, NrGrid);k=16;for K = 1 : numel(XC) xc = XC(K); yc = YC(K); dists = sqrt((coords(:,1)-xc).^2 + (coords(:,2)-yc).^2); [mindist, minidx] = min(dists); center_idx(k) = minidx; end%cluster head selection ends
Best Answer