Q:

How to generate all possible combinations for the column vectors of a matrix, in MATLAB?

If B=[1; 2] and A=[B B B...(n times B)], how to obtain the matrix C corresponding to all the possible combinations between the column vectors of A .i.e. I want to get the combinations between n copies of the same vector.
For example, for n=3:
A =
     1     1     1
     2     2     2

So, C can be obtained using the function from File Exchange 'allcomb(varargin)': 
C=allcomb(A(:,1),A(:,2),A(:,3))
C =
     1     1     1
     1     1     2
     1     2     1
     1     2     2
     2     1     1
     2     1     2
     2     2     1
     2     2     2

In my case n is variable. How to obtain C for any value of n?

A:

You can put the repetitions in a cell, and use the {:} syntax to put all cell elements as inputs to allcomb
n = 3;
B = [1,2];
A = repmat( {B}, n, 1 );
C = allcomb( A{:} ); % allcomb  is FileExchange.
                     % combvec  is a documented alternative.

Output:
C =
 1     1     1
 1     1     2
 1     2     1
 1     2     2
 2     1     1
 2     1     2
 2     2     1
 2     2     2

