📄 cp1002_select_nodes.m
字号:
%
% FUNCTION 10.2 : "cp1002_select_nodes"
%
% This function selects a target node and k reference nodes
% from a set of nodes.
% The function receives in input:
% - The total number of nodes N
% - The number of reference nodes k
% The function returns:
% - The ID of the target node Nx
% - A vector Refs of length k, containing the ID of the
% reference nodes
%
% Programmed by Luca De Nardis
%
function [Nx,Ref] = cp1002_select_nodes(N,k);
% Extraction of the target node
Nx = ceil(N*rand);
Check=zeros(1,N);
for i=1:k
Ref(i) = Nx;
% Check: is Ref(i) different from Nx?
while((Ref(i)==Nx)||(Ref(i)==0))
Ref(i)= ceil(N*rand);
% Check: is Ref(i) already selected?
if(Check(Ref(i)))
Ref(i) = 0;
else
Check(Ref(i))=1;
end
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -