Script that create all combination in a matrix

1 visualización (últimos 30 días)
Lucas S
Lucas S el 19 de Jun. de 2020
Comentada: Lucas S el 19 de Jun. de 2020
Hello,
I have a matrix of 3 elements (3 columns).
A | B | C
Each elements can take 4 values (0, 1, 2, 3). Is there a function or a way to test all possibilities and complete the matrix with all possibilities ? So 3^4 possibilities.
0|1|2
0|1|3
...
...
Thanks
Edit : I miss an information, in my case elements can have same values so i need to take in consideration :
0 | 0 | 0
1 | 1 | 1
0 | 0 | 2
...
  2 comentarios
KSSV
KSSV el 19 de Jun. de 2020
Read about nchoosek.
Lucas S
Lucas S el 19 de Jun. de 2020
Editada: Lucas S el 19 de Jun. de 2020
Thanks it works for all differents values combination ! But is there also a way to generate combination when elements can have same values too like the in the edit of the post ?

Iniciar sesión para comentar.

Respuesta aceptada

Rik
Rik el 19 de Jun. de 2020
Yet another possible solution:
A=0:3;B=0:3;C=0:3;
[A_,B_,C_]=ndgrid(A,B,C);
combs=[A_(:),B_(:),C_(:)];

Más respuestas (1)

madhan ravi
madhan ravi el 19 de Jun. de 2020
doc randperm
  1 comentario
Lucas S
Lucas S el 19 de Jun. de 2020
Editada: Lucas S el 19 de Jun. de 2020
Thanks it works for all differents values combination ! But is there also a way to generate combination when elements can have same values too like the in the edit of the post ?

Iniciar sesión para comentar.

Categorías

Más información sobre Logical 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