MATLAB: Grid structure in wsn..

for loop in grid structured wsngrid structure in wsn

how to use grid structure in wsn, I have understood that how to deploy nodes in grid structured wsn but I am unable to understand how to use 'for loop' for each cell in grid structure,how to do numbering of cells ,which node is in which cell? which cell is above the other cell. how to feed the coordinates of cells in the for loop..

Best Answer

One_grid_info = struct('UID', -inf, 'lat', -inf, 'long', -inf, 'Energy', 10000, 'InputBuffer', [], 'OutputBuffer', []);
nrows = 17;
ncols = 12;
wsn_grid(nrows, ncols) = One_grid_info;
for row = 2:nrows - 1
row_above = row - 1;
row_below = row + 1;
for cols = 2:ncols - 1
col_left = cols - 1;
col_right = cols + 1;
neighbors = sub2ind([nrows, ncols], [row_above, col_left; row_above, col; row_above, col_right; row, col_left; row, col_right; row_below, col_left; row_below, col; row_below, col_right]);
neighbor_info = wsn_grid(neighbors);
do something
end
end