MATLAB: Creating matrix of unique combinations of variables

creating matrix of unique combinations of variables

I need to create a matrix that lists out each combinations of variables in each row.
Assume that I have 5 variables a1, a2, a3, a4, a5 that all have 10 possible values of 0.1:0.1:1, what is an elegant way to list out the 10^5 rows of combinations?
Thank you so much!

Best Answer

nvals = 5;
[a{1:nvals}] = ndgrid(0.1:0.1:1);
Result = cell2mat(cellfun(@(C) C(:), a, 'Uniform', 0));