MATLAB: How to calculate all of the possible combinations of two 1×6 vectors

combinationvector combinations

I have two 1×6 vectors that I am eventually trying to just sum up, but I need to get all of the possible combinations of these vectors before doing so. The vectors will look like so:
V1=[a b c d e f];
V2=[A B C D E F];
What I need is to find all possible combinations of variables that will remain a 1×6 vector. I have been messing around for a while now and I think I have found a way by using various matrices but it seems terribly inefficient. An example of what I am looking for is as follows.
M=[a b c d e f; A b c d e f; A B c d e f; A B C d e f; A B C D e f; A B C D E f; A B C D E F;. . .]
And so on and so forth until all combinations are found. Unfortunately I am not a MATLAB whiz hence the reason I'm reaching out. I'm sure there has to be a much simpler way than what I have been trying. I hope that my question was relatively clear. Any help is much appreciated! Thanks!

Best Answer

V = [V1;V2];
n = size(V,2);
p = dec2bin(0:2^n-1,n)-0+1;
M = zeros(size(p));
for k = 1:size(p,1);
for m = 1:n
M(k,m) = V(p(k,m),m);
end
end