RANDSUBSET

版本 1.2.0.0 (4.4 KB) 作者: Bruno Luong
Return a random subset of k elements of the set of n elements
401.0 次下载
更新时间 2010/6/29

查看许可证

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 CenterMATLAB Answers 中查找有关 Random Number Generation 的更多信息

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.2.0.0

Change the description

1.1.0.0

Mex engine

1.0.0.0