Is there an equivalent function for tuples in Matlab as there is for Mathematica?
See the first example:
http://reference.wolfram.com/language/ref/Tuples.html
I just mean the outputs and not necessarily the braces.
Thank you.
Is there an equivalent function for tuples in Matlab as there is for Mathematica?
See the first example:
http://reference.wolfram.com/language/ref/Tuples.html
I just mean the outputs and not necessarily the braces.
Thank you.
As I stated in comments, you only need to adapt this answer. You can do it as follows:
function y = tuples(x, n)
y = cell(1,n);
[y{end:-1:1}] = ndgrid(x);
y = cat(n+1, y{:});
y = reshape(y, [], n);
This gives a matrix where each row is a tuple. For example:
>> tuples([1 2 5], 2)
ans =
1 1
1 2
1 5
2 1
2 2
2 5
5 1
5 2
5 5