📄 topology.m
字号:
function [T,R]=topology
clear all;
clf;
a=10; % uniform distribution between 0 and a
N=8;
trange=1;
T=unifrnd(0,a,2,N);% there are totally N transmission nodes in the network
plot(T(1,:),T(2,:),'ro','MarkerSize',7);
axis([0,10,0,10]);
R=ones(2,N);
c=ones(2,N);
incide=zeros(1,N);
i=1;
while i<N+1
c1=unifrnd(0,a,2,1);
c(1,:)=c1(1,1);
c(2,:)=c1(2,1);
incidefind=find(incide);
for j=1:1:length(incidefind)
c(1,incide(1,j))=100;
c(2,incide(1,j))=100;
end
abst=((T(1,:)-c(1,:)).^2+(T(2,:)-c(2,:)).^2).^0.5;
[minvalue,incide1]=min(abst);
if minvalue<trange
R(1,incide1)=c1(1,1);
R(2,incide1)=c1(2,1);
incide(1,i)=incide1;
i=i+1;
end %the receiving node is in the transmission range
end %there are totally N receiving nodes
hold on;
plot(R(1,:),R(2,:),'bo','MarkerSize',7);
for m=1:N
plot([T(1,m) R(1,m)],[T(2,m) R(2,m)],'r');
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -