Weighted sampling without replacement
I have a population p of indices and corresponding weights in vector w . I want to get k samples from this population without replacement where the selection is done proportional to the weights in random. I know that randsample can be used for selection with replacement by saying J = randsample(p,k,true,w) but when I call it with parameter false instead of true , I get ??? Error using ==> randsample at 184 Weighted sampling without replacement is not supported. I wrote my own function as discussed in here : p = 1:n; J = zeros(1,k); for i = 1:k J(i) = randsample(p,1,true,w); w(p == J(i)) = 0;