If I have a vector [1 2 3] and I want all combinations of these values along 6 elements so I will have (3^6) combinations in one vector, How can I do?

1 visualización (últimos 30 días)
If I have a vector [1 2 3] and I want all combinations of these values along 6 elements so I will have (3^6) combinations in one vector, How can I do?

Respuesta aceptada

Guillaume
Guillaume el 31 de Mayo de 2017
Most likely there's already an implementation on the FileExchange. Otherwise, it's easy to implement:
elements = [1 2 3];
count = 6;
combs = cell(1, count);
[combs{:}] = ndgrid(elements);
combs = reshape(cat(count + 1, combs{:}), [], count)

Más respuestas (1)

ES
ES el 31 de Mayo de 2017
perms
example:
perms(repmat([1 2 3], 1,2))

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by