RANDSUBSET
版本 1.2.0.0 (4.4 KB) 作者:
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!
引用格式
Bruno Luong (2025). RANDSUBSET (https://ww2.mathworks.cn/matlabcentral/fileexchange/28002-randsubset), MATLAB Central File Exchange. 检索时间: .
MATLAB 版本兼容性
创建方式
R2010a
兼容任何版本
平台兼容性
Windows macOS Linux类别
在 Help Center 和 MATLAB Answers 中查找有关 Random Number Generation 的更多信息
标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!