MATLAB: How to i get combination of 4 non-consecutive numbers

www.google.com

i have the following numbers and want all possible combinations of these numbers
a=[2 4 6]
i need output as
a=
2 2 2 2
2 2 2 4
2 2 4 4
2 4 4 4
2 2 2 6
2 2 6 6
2 6 6 6
2 4 6 4
etc....

Best Answer

[T1, T2, T3, T4] = ndgrid(a);
output = [T1(:), T2(:), T3(:), T4(:)]