### Highlights from CARTPROD: Cartesian product of multiple sets

4.2

4.2 | 5 ratings Rate this file 16 Downloads (last 30 days) File Size: 1.47 KB File ID: #5475

# CARTPROD: Cartesian product of multiple sets

12 Jul 2004 (Updated )

Returns a matrix containing the cartesian product of multiple input sets.

File Information
Description

CARTPROD Cartesian product of multiple sets. (The cartesian product of multiple input sets is a larger set containing every ordered combination of the input set elements. See example below.)

X = CARTPROD(A,B,C,...) returns the cartesian product of the sets A,B,C, etc, where A,B,C, are numerical vectors.

Example: A = [-1 -3 -5];
B = [10 11];
C = [0 1];

X = cartprod(A,B,C)
X =

-5 10 0
-3 10 0
-1 10 0
-5 11 0
-3 11 0
-1 11 0
-5 10 1
-3 10 1
-1 10 1
-5 11 1
-3 11 1
-1 11 1

This function requires IND2SUBVECT, also available (I hope) on the MathWorks File Exchange site.

Acknowledgements

This file inspired Setprod.

MATLAB release MATLAB 6.5 (R13)
Other requirements This function requires IND2SUBVECT, also available (I hope) on the MathWorks File Exchange site.
29 Dec 2011

I need to use the cartesian product

28 Sep 2010

I need to make a cartesian roduct of a vector for variable dimension but i cant find a code for this purpose. can somebody help me please?!!

05 Nov 2009

I made a slight change to this file. I replaced your varargin with a cell array, in which each row is a vector. This might also be useful for other people when they don't know how many vectors need to be combined.

07 Jul 2005
09 Jun 2005

Thanks for the m file, it was exact that for what i was searching

28 May 2005

This m file work well on my problem in Communication toolbox to generate random noise. Thanks so much David Fass