How can I divide area into 12 sectors and deploy its nodes_locations ?
Afficher commentaires plus anciens
Hi,
Below is the Matlab-code to equally divided Area into 8 parts as in the picture below

% %Inputs: nodes_location: the coordinates of the nodes.
% Tx: Transmission powers of the nodes.
% threshold: the chosen threshold for clustering.
%Outputs: CH_I: Index of cluster heads.
% CH_T: Transmission powers of cluster heads.
% CM_T: Transmission powers of cluster members.
% CM_I: Index of cluster members.
% clusters: Indicates the size of each cluster.
function [CH_I , CH_T , CM_T , CM_I , clusters] = clustering(nodes_location , Tx , threshold)%H i add ce and cnn
global cluster_size
index = find(Tx > threshold);
cn = nodes_location(index , :);
clusters = zeros(8 , 50);
CH_I = [];
CH_T = [];
CM_L = [];
CM_T = [];
%Sector 1
index_s1 = find(cn(: , 1) >= 0 & cn(: , 1) <= cn(: , 2) & cn(: , 2) >= 0);
a_index_s1 = index(index_s1);
sector1 = cn(index_s1 , :);
Tx_sector1 = Tx(a_index_s1);
%Sector 2
index_s2 = find(cn(: , 1) >= 0 & cn(: , 1) > cn(: , 2) & cn(: , 2) >= 0);
a_index_s2 = index(index_s2);
sector2 = cn(index_s2 , :);
Tx_sector2 = Tx(a_index_s2);
%Sector 8
index_s8 = find(cn(: , 1) < 0 & abs(cn(: , 1)) <= cn(: , 2) & cn(: , 2) >= 0);
a_index_s8 = index(index_s8);
sector8 = cn(index_s8 , :);
Tx_sector8 = Tx(a_index_s8);
%Sector 7
index_s7 = find(cn(: , 1) < 0 & abs(cn(: , 1)) > cn(: , 2) & cn(: , 2) >= 0);
a_index_s7 = index(index_s7);
sector7 = cn(index_s7 , :);
Tx_sector7 = Tx(a_index_s7);
%Sector 3
index_s3 = find(cn(: , 1) >= 0 & cn(: , 1) > abs(cn(: , 2)) & cn(: , 2) < 0);
a_index_s3 = index(index_s3);
sector3 = cn(index_s3 , :);
Tx_sector3 = Tx(a_index_s3);
%Sector 4
index_s4 = find(cn(: , 1) >= 0 & cn(: , 1) <= abs(cn(: , 2)) & cn(: , 2) < 0);
a_index_s4 = index(index_s4);
sector4 = cn(index_s4 , :);
Tx_sector4 = Tx(a_index_s4);
%Sector 5
index_s5 = find(cn(: , 1) < 0 & abs(cn(: , 1)) <= abs(cn(: , 2)) & cn(: , 2) < 0);
a_index_s5 = index(index_s5);
sector5 = cn(index_s5 , :);
Tx_sector5 = Tx(a_index_s5);
%Sector 6
index_s6 = find(cn(: , 1) < 0 & abs(cn(: , 1)) > abs(cn(: , 2)) & cn(: , 2) < 0);
a_index_s6 = index(index_s6);
sector6 = cn(index_s6 , :);
Tx_sector6 = Tx(a_index_s6);
How the area can be split and deploy nodes into more parts, for instance (12) like pic below

%
2 commentaires
Tamoor Shafique
le 26 Fév 2022
did you get the answer to this?
Walter Roberson
le 26 Fév 2022
yes I posted code below https://www.mathworks.com/matlabcentral/answers/393205-how-can-i-divide-area-into-12-sectors-and-deploy-its-nodes_locations#comment_554235
Réponses (2)
Walter Roberson
le 7 Avr 2018
0 votes
I would suggest converting into polar form relative to the center of the circle, and then dividing according to groups of 2*pi/12 radians.
1 commentaire
Hassan Al-Khateeb
le 7 Avr 2018
Modifié(e) : Walter Roberson
le 7 Avr 2018
Hassan Al-Khateeb
le 7 Avr 2018
0 votes
1 commentaire
Walter Roberson
le 7 Avr 2018
[th, r] = cart2pol( x - xc, y - yc );
sector_number = mod(floor(th / (2*pi/12) ) - 1, 12) + 1;
Catégories
En savoir plus sur WSNs dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!