How to make combinations of given condition?
1 回表示 (過去 30 日間)
古いコメントを表示
Hi, all,
For example, if I want to make all combination of 5-dim vectors have only 2 two's, other entries are all 0. Is there a command in Matlab can do it? That is 22000 20200 20020 20002 02200 02020 02002 00220 00202 00022
Thanks.
0 件のコメント
採用された回答
Andrei Bobrov
2012 年 12 月 28 日
編集済み: Andrei Bobrov
2012 年 12 月 28 日
k = dec2bin(0:sum(pow2(0:4)))-'0';
out = 2*k(sum(k,2) == 2,:);
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!