Generating all combinations with repetition using MATLAB
We can use the bijection mentioned in the wikipedia article, which maps combinations without repetition of type n+k-1 choose k to k-multicombinations of size n. We generate the combinations without repetition and map them using bsxfun(@minus, nchoosek(1:n+k-1,k), 0:k-1);. This results in the following function: function combs = nmultichoosek(values, k) %// Return number of multisubsets or … Read more