Borrar filtros
Borrar filtros

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 ma

1 visualización (últimos 30 días)
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 on
plot(Y,X,'k')
hold off
set(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

Respuesta aceptada

Walter Roberson
Walter Roberson el 17 de Jun. de 2015
Editada: Walter Roberson el 21 de En. de 2021
[XC, YC] = ndgrid(1:2:NrGrid, 1:2:NrGrid);
area_center_idx = zeros(size(XC));
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);
area_center_idx(k) = minidx;
end
This has the same limitation as before: that since your nodes are randomly distributed there is a possibility (that decreases with the number of nodes) that the closest node to the area center is really in the next grid cell over, because the maximum diagonal distance is greater than the horizontal or vertical distance. Besides, you could randomly end up with no nodes at all in a given area and so the node closest to the center of the area would have to be in a different cell.

Más respuestas (0)

Categorías

Más información sobre WSNs en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by