Generate all possible permutations including repeats
21 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Alec Bledsoe
am 25 Okt. 2023
Bearbeitet: Bruno Luong
am 25 Okt. 2023
I am trying to generate all possible combinations of 0,1,2 including repeats.
I have tried:
F = [0,1,2];
perms(F)
That works but it only gives the combinations with no repeats:
2 1 0
2 0 1
1 2 0
1 0 2
0 2 1
0 1 2
Including repeats there should be 27 combinations instead of just 6 without repeats
0 Kommentare
Akzeptierte Antwort
Bruno Luong
am 25 Okt. 2023
Bearbeitet: Bruno Luong
am 25 Okt. 2023
F = [0,1,2];
combinations(F,F,F)
0 Kommentare
Weitere Antworten (1)
Voss
am 25 Okt. 2023
F = [0,1,2];
n_values = numel(F);
n_combos = n_values^n_values;
M = F(1+dec2base(0:n_combos-1,n_values)-'0');
disp(M);
0 Kommentare
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!