forked from mwgeurts/libra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandomset.m
executable file
·40 lines (37 loc) · 1.15 KB
/
randomset.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function [ranset,seed] = randomset(tot,nel,seed)
%RANDOMSET draws randomly a subsample of nel cases out of tot.
%(It is called if not all (p+1)-subsets out of n will be considered.)
%
% Required input arguments:
% tot : The total number of observations to consider
% nel : The number of observations that the subsample must contain
% Optional input arguments:
% seed : To define the state of the generator (default=0)
% (0 sets the generator to its default initial state)
%
% Output arguments:
% ranset : Random subset of nel cases out of tot.
% seed : The corresponding state.
%
%
% I/O:
% [ranset,seed]=randomset(n,n/2,0)
%
% This function is part of LIBRA: the Matlab Library for Robust Analysis,
% available at:
% http://wis.kuleuven.be/stat/robust
if nargin==2
seed=0;
end
ranset=zeros(1,nel);
for j=1:nel
[random,seed]=uniran(seed);
num=floor(random*tot)+1;
if j > 1
while any(ranset==num) %number already in ranset: redraw
[random,seed]=uniran(seed);
num=floor(random*tot)+1;
end
end
ranset(j)=num;
end