How can I generate all possible combinations of a vector containing specific numbers in it?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Arjun M
am 3 Apr. 2021
Kommentiert: Arjun M
am 3 Apr. 2021
For example, consider this vector A
A = [1 1 1 0 0 0 0 0].
I need all combinations of this vector so that there are 3 ones and 5 zeros. the number of combinations is 56 here.
I tried using randperm but I'm getting repeated vectors.
Kindly help solve this
0 Kommentare
Akzeptierte Antwort
Bruno Luong
am 3 Apr. 2021
J=nchoosek(1:8,3);
[m,n]=size(J);
I=repmat((1:m)',1,n);
accumarray([I(:) J(:)],1)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu MATLAB Coder 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!