How to make combinations of given condition?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Andrei Bobrov
am 28 Dez. 2012
Bearbeitet: Andrei Bobrov
am 28 Dez. 2012
k = dec2bin(0:sum(pow2(0:4)))-'0';
out = 2*k(sum(k,2) == 2,:);
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!