Given a vector, I would like to sample without replacement elements from it repeatedly.
Show older comments
Given a (m x 1) vector v , I would like to ,randomly without replacement, sample s elements from it. I know I can use randsample(v,s) if I were to do this once. However, I want to do this repeatedly without using a for loop (i.e vectorization) so that it is fast.
1 Comment
Accepted Answer
More Answers (1)
Bruno Luong
on 21 Aug 2020
Edited: Bruno Luong
on 21 Aug 2020
v = 'a':'z' % your vector
n = 10; % number of "loop"
s = 3; % number of drawing without replacement
[~,ir] = maxk(rand(n,length(v)),s,2);
r = v(ir)
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!