This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Cartesian product

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.


combinat::cartesianProduct(S1, …)


combinat::cartesianProduct(S1, ...) returns the cartesian product of the sets or lists S1, … as a list of lists.

The cartesian product of S1 through Sn consists of all lists of length n whose i-th entry is an operand of the set or list Si, for 1 ≤ in.

Any integer k among the arguments is identified with the set of the first k positive integers.

The ordering of the output is unspecified.


Example 1

The following calls are equivalent:

combinat::cartesianProduct({1, 2}, {a, b}), 
combinat::cartesianProduct(2, [b, a])



Set, list, or nonnegative integer

Return Values

List of lists, each of them having as many operands as there were arguments passed to combinat::cartesianProduct.

Was this topic helpful?