MATLAB: How to perform nonrepeating bootstrap resampling in MATLAB Statistics and Machine Learning Toolbox Resampling with bootstrap contains the possibility that repeated samples might occur. I would like to sample a set to obtain a subset in which the elements of the subset do not contain repeated results. Best Answer A workaround is to generate a set of unique random indexes.See the following code for an example:N = 1000; % Size of your total set Nsub = 5; % Size of the subsetnu = 0;while(length(nu) < Nsub)x = round(.5 + (N - eps(N+.5))*rand(1,10*Nsub));[b1, nu, n1] = unique(x, 'first'); endindexi = nu(1:Nsub) % Unique and random indexes for subset into % the larger set. Related SolutionsMATLAB: How to sort a vector in a random manner in MATLAB To sort the elements of a vector randomly you can use the RANDPERM() function.RANDPERM(n) returns a random permutation of the integers 1:n.a = [1 2 3 4 5];a_rand = a(randperm(length(a))); MATLAB: Setting non-repeated elements from two related matrices to NaN A = [1 2 1; 3 5 1; 2 3 6];B = [1 2 3; 4 5 6; 7 8 9];uniqueA = unique(A);counts = histcounts(A,[uniqueA;Inf]);nanIndex = ismember(A,uniqueA(counts==1));A(nanIndex) = NaN;B(nanIndex) = NaN; Related QuestionGenerating random numbers in orderDo I get correlated random numbers when I invoke RANDN after incrementing the seed by a small number in MATLAB 7.5 (R2007b)Non-repeating random integer generator with a seedCreating permutations of all possible non-repeated combinations within N elementsHow to generate unique random samples for the following scenario
Best Answer