MATLAB: Finding all possible combinations of a matrix

combinationsmatrixmatrix manipulation

Hello Everyone,
I have the following matrix:
mat=[0 0 0 0;1 1 1 1;2 2 2 2;3 3 3 3]
and i want to create a new matrix from it that would have all possible combinations: [ 0 0 0 0; 0 0 0 1; 0 0 0 2; 0 0 0 3; 0 0 1 0; 0 0 2 0; . . . ;3 3 3 3]
How can I do that?
Thanks a lot in advance
Best Regards, Sameh

Best Answer

Hello All,
for "U=4" --> the inputs of the input matrix (0,1,2,3) and "depth=4" --> (number of columns of the output matrix)
I have found a simple answer, which is also generic for other values of "U" and "depth":
combs = dec2base(0:power(U,depth)-1,U) - '0';
Thank you all for your replies and I hope that my answer or yours would be of help to others as well.
Best Regards,
Sameh