RANDSUBSET
Versione 1.2.0.0 (4,41 KB) da
Bruno Luong
Return a random subset of k elements of the set of n elements
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!
Cita come
Bruno Luong (2025). RANDSUBSET (https://it.mathworks.com/matlabcentral/fileexchange/28002-randsubset), MATLAB Central File Exchange. Recuperato .
Compatibilità della release di MATLAB
Creato con
R2010a
Compatibile con qualsiasi release
Compatibilità della piattaforma
Windows macOS LinuxCategorie
Scopri di più su Random Number Generation in Help Center e MATLAB Answers
Tag
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Scopri Live Editor
Crea script con codice, output e testo formattato in un unico documento eseguibile.
