How to return 'X' number of unique subsets (combinations) of 'N' numbers taken 'K' at a time
4 ビュー (過去 30 日間)
古いコメントを表示
I need to return X number of unique combinations of N numbers (i.e., vector V of length N) taken K at a time.
I can't use 'nchoosek' because I don't want ALL unique combinations. I just want X number of them and 'nchoosek' will crash if I enter the actual values for V and K because V is too large.
Here's an example, with more descriptive variable names…
origSet = rand(1,500); %the full original (example) set of numbers
desNumComb = 10000; %the number of unique combinations/subsets that I want to end up with
subsetSize = 10; %the desired size for each combination/subset
allCombos = nchoosek(1:length(origSet), subsetSize); %will return ALL possible combinations (if it ran)
subsetInds = allCombos(desNumComb,:); %the indices for each of the desNumComb subsets
Worth mentioning is that the size of the original set of numbers [i.e., length(origSet) ], the desired subset size [i.e., subsetSize], and the desired number of unique combinations [i.e., desNumComb] will possibly vary every time I loop through, which will be many times.
Thanks in advance to all.
Cheers, John
2 件のコメント
Walter Roberson
2015 年 7 月 23 日
Which X subsets? The "first" X subsets under some specific ordering? X random subsets? Are you using this to iterate through all the possibilities in batches?
採用された回答
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!