RANDSUBSET

Return a random subset of k elements of the set of n elements
401 Downloads
Aktualisiert 29. Jun 2010

Lizenz anzeigen

A = RANDSUBSET(N, K) is equivalent to

ALLSUBSETS = NCHOOSEK(1:N,K);
A = ALLSUBSETS(RANDI(NCHOOSEK(N,K)));

% or

A = RANDPERM(N);
A = SORT(A(1:k));

This function can also be used to generate random sampling without replacement by calling RANDPERM on the output.

It works advantageously with large N (but "reasonable" K), and fast!

Zitieren als

Bruno Luong (2024). RANDSUBSET (https://www.mathworks.com/matlabcentral/fileexchange/28002-randsubset), MATLAB Central File Exchange. Abgerufen .

Kompatibilität der MATLAB-Version
Erstellt mit R2010a
Kompatibel mit allen Versionen
Plattform-Kompatibilität
Windows macOS Linux
Kategorien
Mehr zu Random Number Generation finden Sie in Help Center und MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Veröffentlicht Versionshinweise
1.2.0.0

Change the description

1.1.0.0

Mex engine

1.0.0.0