Main Content

combvec

Create all combinations of vectors

Description

example

A = combvec(A1,A2,...) takes any number of inputs A, where each input Ai has Ni columns, and returns a matrix of (N1*N2*...) column vectors, where the columns consist of all combinations found by combining one column vector from each input Ai.

Examples

collapse all

This example shows how to generate a matrix that contains all combinations of two matrices, a1 and a2.

Create the two input matrices, a1 and a2. Then call the combvec function to generate all possible combinations.

a1 = [1 2 3; 4 5 6];
a2 = [7 8; 9 10];
a3 = combvec(a1,a2)
a3 =

     1     2     3     1     2     3
     4     5     6     4     5     6
     7     7     7     8     8     8
     9     9     9    10    10    10

Input Arguments

collapse all

Input matrix of which you want to calculate all combinations, specified as a matrix with N1 column vectors.

Input matrix of which you want to calculate all combinations, specified as a matrix with N2 column vectors.

Output Arguments

collapse all

Output matrix, returned as a matrix of (N1*N2*...) column vectors, where the columns consist of all combinations found by combining one column vector from each input Ai.

Introduced before R2006a