1。程序实现
设数据存放于向量a中,需要重复n次简单随机采样,程序及说明如下:
m=length(a); %dimension
idx= ceil(m*rand(1,n)) ; %generate n random index between 1 and m
b = a(idx) ; % sampling
2。自带函数
RANDSAMPLE Random sample, with or without replacement.
Y = RANDSAMPLE(N,K) returns Y as a vector of K values sampled
uniformly at random, without replacement, from the integers 1:N.
Y = RANDSAMPLE(POPULATION,K), where POPULATION is a vector of two or more
values, returns K values sampled uniformly at random, without replacement,
from the values in the vector POPULATION.
Y = RANDSAMPLE(...,REPLACE) returns a sample taken with replacement if
REPLACE is true, or without replacement if REPLACE is false (the default).
Y = RANDSAMPLE(...,true,W) returns a weighted sample, using positive
weights W, taken with replacemen