Suppose I have a list of length 2k
, say {1,2,...,2k}
. The number of possible ways of grouping the 2k
numbers into k
(unordered) pairs is n(k) = 1*3* ... *(2k-1)
. So for k=2
, we have the following three different ways of forming 2 pairs
(1 2)(3 4)
(1 3)(2 4)
(1 4)(2 3)
How can I use Matlab to create the above list, i.e., create a matrix of n(k)*(2k)
such that each row contains a different way of grouping the list of 2k
numbers into k
pairs.