title: Complete set of combinations combining 3 set
body: <p>I need to generate the complete set of combinations obtained  combining three different subset:</p>
  
  <ul>
  <li><strong>Set 1</strong>: choosing any 4 numbers from a vector of 13 elements.</li>
  <li><strong>Set 2</strong>: choosing any 2 numbers from a vector of 3 elements. </li>
  <li><strong>Set 3</strong>: choosing any 2 numbers from a vector of 9 elements. </li>
  </ul>
  
  <h3>Example: sample 3 from vector of 4 (H=3 and L=4) for the Set A, H=2 L=3 for the Set B and H=2 L=4 for the Set B:</h3>
  
  <pre><code>           4    4   4
             3    4   4
             3    3   4
             3    3   3
             2    4   4
             2    3   4
             2    3   3
             2    2   4
  Set A =    2    2   3
             2    2   2
             1    4   4
             1    3   4
             1    3   3
             1    2   4
             1    2   3
             1    2   2
             1    1   4
             1    1   3
             1    1   2
             1    1   1
  
             3    3
             2    3
  Set B =    2    2
             1    3
             1    2
             1    1
  
             4    4
             3    4
             3    3
             2    4
  Set C =    2    3
             2    2
             1    4
             1    3
             1    2
             1    1
  </code></pre>
  
  <p><code>[Set A] = [20 x 3]</code>, <code>[Set B] = [6 x 2]</code>, <code>[Set C] = [10 x 2]</code>. Then I need to obtain all possible combinations from these three sets: <code>AllComb = [Set A] x [Set B] x [Set C] = [1200 x 8]</code>. The <code>AllComb</code> matrix will be like this:</p>
  
  <pre><code>4   4   4   |   3   3   |   4   4
  4   4   4   |   3   3   |   3   4
  4   4   4   |   3   3   |   3   3
  4   4   4   |   3   3   |   2   4
  4   4   4   |   3   3   |   2   3
  4   4   4   |   3   3   |   2   2
  4   4   4   |   3   3   |   1   4
  4   4   4   |   3   3   |   1   3
  4   4   4   |   3   3   |   1   2
  4   4   4   |   3   3   |   1   1
  4   4   4   |   2   3   |   4   4
  4   4   4   |   2   3   |   3   4
  4   4   4   |   2   3   |   3   3
  4   4   4   |   2   3   |   2   4
  4   4   4   |   2   3   |   2   3
                   .
                   .
                   .
  1   1   1   |   1   1   |   1   1
  </code></pre>
  
  <p>Unfortunately I can not use the same number for the sets since I need to substitute the numbers like that:</p>
  
  <ul>
  <li>For <code>Set A</code>: 1 = 10, 2 = 25, 3 = 30 and 4 = 45</li>
  <li>For <code>Set B</code>: 1 = 5, 2 = 20 and 3 = 35</li>
  <li>For <code>Set C</code>: 1 = 10, 2 = 20, 3 = 30 and 4 = 50</li>
  </ul>
  
  <p>Any ideas? Real case sets will often lead to an <code>AllComb</code> matrix ~[491 400 x 8] so vectorized solutions will be gladly accepted.</p>
  
  <p><em>Note: Each set is obtained with the following code:</em></p>
  
  <pre><code>a = combnk(1:H+L-1, H);
  b = cumsum([a(:,1)  diff(a,[],2) - 1],2);
  </code></pre>
  
  <h3>What is <code>H</code> and <code>L</code>?</h3>
  
  <p><code>H</code> are the hoppers of a MultiheadWeigher (MHW) machines. I have a MHW with <code>H=8</code> and I need to deliver in each of these hoppers some materials. If I need to deliver just one type of material all possibile combinations are <code>(L+H-1)!/(H!(L-1)!)</code> and i compute them with the code write above (<code>a</code> and <code>b</code>). Now, suppose to have 3 different product then we have 4 hoppers for product A, 2 for B and 2 for C. Product A in the first 4 hoppers can assume values <code>10:10:130</code>, Product B <code>10:10:30</code> and c <code>10:10:90</code>. Then the number of steps are for A <code>L=13</code>, B <code>L=3</code> and C <code>L=9</code></p>