gusucode.com > UWB_matlab源码程序 > CP1002/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