No BSD License  

Highlights from
CARTPROD: Cartesian product of multiple sets

4.2

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

CARTPROD: Cartesian product of multiple sets

by David Fass

 

12 Jul 2004 (Updated 16 Jul 2004)

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

| Watch this File

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 submission has inspired the following:
SETPROD
MATLAB release MATLAB 6.5 (R13)
Other requirements This function requires IND2SUBVECT, also available (I hope) on the MathWorks File Exchange site.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (6)
28 May 2005 Nguyen Tat Duc Chinh

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

09 Jun 2005 Jadran Dobric

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

07 Jul 2005 Norbert Zbroniec  
05 Nov 2009 Kshanti

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.

28 Sep 2010 Mehrdad Alipour

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?!!

29 Dec 2011 Michael

I need to use the cartesian product

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
sets David Fass 22 Oct 2008 07:27:30
cartesian David Fass 22 Oct 2008 07:27:30
product David Fass 22 Oct 2008 07:27:30
permutation David Fass 22 Oct 2008 07:27:30

Contact us at files@mathworks.com