?? 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 + -