combs: Generate all possible combinations of vector elements
Version 1.0.0 (1.34 KB) by
Carlos Souto
Generate all possible combinations of the elements of a given vector.
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
Cite As
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. Retrieved .
MATLAB Release Compatibility
Created with
R2021a
Compatible with any release
Platform Compatibility
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0 |