How to use combinatorial function with different element possibilities?
4 ビュー (過去 30 日間)
古いコメントを表示
I would like to have all the possible combinations of the elements of a vector. However, I don't know how to use the nchoosek function when each element of the vector is not fixed. It can be either 0 or 1. For example:
0 0 0 0, 0 0 0 1, 0 0 1 1, 0 1 1 1, 1 1 1 1, 1 1 0 0, 1 0 1 0 etc...
Is there a function which can capture different possible elements? Thank you so much in advance!
0 件のコメント
回答 (1 件)
Jan
2017 年 3 月 15 日
編集済み: Jan
2017 年 3 月 15 日
You can use http://www.mathworks.com/matlabcentral/fileexchange/26242-vchoosekro, bu it needs to be compiled. Then:
v = [0,1];
n = 4;
R = VChooseKRO(v, n)
If compiling is a problem, use this http://www.mathworks.com/matlabcentral/fileexchange/24325-combinator-combinations-and-permutations .
index = combinator(length(v), n,'p','r')
R = v(index); % Untested code
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Discrete Math についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!