combs: Generate all possible combinations of vector elements

Generate all possible combinations of the elements of a given vector.
58 download
Aggiornato 22 set 2021

Visualizza la licenza

Generate all possible combinations of the elements of a given vector.
table = combs(v, k) returns a matrix containing all possible combinations of the elements of vector v selected k times (includes repetitions). Matrix table has k columns and n^k rows, where n is the number of elements of vector v.
>> combs([-1, 0, 1], 3)
ans =
-1 -1 -1
-1 -1 0
-1 -1 1
-1 0 -1
-1 0 0
-1 0 1
-1 1 -1
-1 1 0
-1 1 1
0 -1 -1
0 -1 0
0 -1 1
0 0 -1
0 0 0
0 0 1
0 1 -1
0 1 0
0 1 1
1 -1 -1
1 -1 0
1 -1 1
1 0 -1
1 0 0
1 0 1
1 1 -1
1 1 0
1 1 1

Cita come

Carlos Souto (2024). combs: Generate all possible combinations of vector elements (https://www.mathworks.com/matlabcentral/fileexchange/99684-combs-generate-all-possible-combinations-of-vector-elements), MATLAB Central File Exchange. Recuperato .

Compatibilità della release di MATLAB
Creato con R2021a
Compatibile con qualsiasi release
Compatibilità della piattaforma
Windows macOS Linux
Tag Aggiungi tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Versione Pubblicato Note della release
1.0.0