I want to create a table which contains all possible combinations, order is important, of N numbers in sets of k using matlab.
I tried Combinations = combntns(set,subset)
and Combinations = perms(v)
and Combinations = combnk(v,k)
but in those order is not important.
An example:
nchoosek(1:5,3)
ans =
1 2 3
1 2 4
1 2 5
1 3 4
1 3 5
1 4 5
2 3 4
2 3 5
2 4 5
3 4 5
While it should also include
1 3 2
1 4 2
1 5 2
1 3 5
1 5 3
...
The number of possible combinations is given by the following by the function:
N!/(N-k)!
Is there a possible way to do it this using matlab functions?