⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cluster_head.m

📁 无线传感器网络LEACH算法的matlab模型
💻 M
字号:
function [head_coordinate,new_mark]=cluster_head(XY,current_rounds)
global old_mark p left_energy threshold_energy_head
rand('state',sum(100*clock));
[m,n]=size(XY);%计算行数和列数
amount_node=n;%节点数目
threshod_p=p/(1-p*(current_rounds-1));
head=zeros(1,amount_node);
head=rand(1,amount_node);
j=1;%簇头计数器
%head_coordinate=zeros(2,amount_node);
new_mark=zeros(1,amount_node);
amount_head=0;
for i=1:amount_node
    if head(i)<threshod_p&old_mark(i)==0&left_energy(i)>threshold_energy_head
        amount_head=amount_head+1;
    end
end
head_coordinate=zeros(2,amount_head);
for i=1:amount_node
    if head(i)<threshod_p&old_mark(i)==0&left_energy(i)>threshold_energy_head
        head_coordinate(:,j)=XY(:,i);%簇头坐标矩阵
        old_mark(i)=1; %簇头位设为1
        new_mark(i)=1;
        j=j+1; 
    end
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -