Problem 42790. Full combinations
Given n input vectors x1, x2, …, xn, generate a p*n matrix y whose rows contain all element-wise combinations of the vectors x1, x2, …, xn, where p = numel(x1)*numel(x2)*…* numel(xn). The rows of y are organized in an "increasing" ordering; see examples below.
- Example 1 (character array, n = 2): Input: x1 = 'ab'; x2 = 'cde'; Output:
y = ['ac' 'ad' 'ae' 'bc' 'bd' 'be']
- Example 2 (numeric array, n = 3): Input: x1 = [0 1], x2 = [0 1]; x3 = [0 1]; Output:
y = [0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1]
You may assume that all inputs are valid vectors whose lengths are at least 1.
Note: The Statistics and Machine Learning toolbox provides two useful functions for full factorial design, namely ff2n (for binary case) and fullfact (for general cases). However, they do not directly accomplish the task in Example 1. The purpose of this problem is to create a toolbox independent function to achieve our goal. Have fun!
Solution Stats
Problem Comments
-
2 Comments
It would be better if the test suite did not rely on a particular ordering of the rows. You could use isempty(setxor(myfullfact(...), y_correct, 'rows')) instead of isequal(...)
Thanks for your suggestion. But I prefer an "increasing" ordering of the rows because that could be more useful in some applications. I have made it clear in the problem description that ordering is required.
Solution Comments
Show commentsGroup

Matrix Manipulation II
- 19 Problems
- 77 Finishers
- matrix zigzag
- Given a matrix, swap the 2nd & 3rd columns
- Matrix of Multiplication Facts
- MatCAT - Reconstruct X from Its X-rays
- Given a matrix, swap the 2nd & 3rd columns
- subtract central cross
- frame of the matrix
- Remove entire row and column in the matrix containing the input values
- Enlarge array
- Too Many Zeros, Dump Them!
- Convert matrix to 3D array of triangular matrices
- A matrix of extroverts
- Matrix multiplication across rows
- Replace Nonzero Numbers with 1
- Magnet and Iron
- Must be in the front row...
- Go to the head of the class!
- Matrix of Multiplication Facts
- Hankelize a matrix
- Write a function man that takes a row vector v and returns a matrix H as follows..
- Toeplitize a matrix
Problem Recent Solvers27
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!