One possiblity combvec
. This function gives you all combinations of the column vectors of the input matrices. You can do the following to get the combinations of elements in your random vectors.
vector1 = random('Normal', 0, 1, 1, 5);
vector2 = random('Normal', 0, 1, 1, 5);
vector3 = random('Normal', 0, 1, 1, 5);
M = combvec(vector1, vector2, vector3);
M
will be a 3x125 matrix where each column is one element from vector1
, one element from vector2
, and one element from vector3
If you want n
vectors, where n
is a random number, an alternative approach is using cartesian product to index into the vectors.
n = randi(5);
all_vectors = random('Normal', 0, 1, n, 5);
indices = mat2cell(repmat([1:5], n, 1), ones(n ,1))';
[x y z] = ndgrid(indices{:});
cartProd = [x(:), y(:), z(:)];
M = all_vectors(cartProd);