I'm trying to create a combination with repetitions but in smaller poriions. The idea is that I want to work with a large table of all possible combinations but due to its space consumption, I thought of generating that same table but split in parts. I would work on the first part (i.e. the first 1000 rows), then delete, and work on the next 1000 rows of the table.
This is an example of a combination w/ repetitions:
I need this result as shown below without first generating the whole combination.
Of course, the table are much larger than this but I'm not sure how to approach this. After some search, I found a nice code that generates B as shown on the top but I'm not very sure how to break it down without generating the big table first.
A = [1 2];
B = nmultichoosek(A,2)
function combs = nmultichoosek(values, k)
n = values;
combs = nchoosek(n+k-1,k);
n = numel(values);
combs = bsxfun(@minus, nchoosek(1:n+k-1,k), 0:k-1);
combs = reshape(values(combs),,k);
Let me know if the question doesn't make sense.