How to create combinations of rows in an array?

2 visualizaciones (últimos 30 días)
Anh Nguyen
Anh Nguyen el 4 de Dic. de 2020
Comentada: Rik el 9 de Dic. de 2020
Hi all,
Here is my problem:
I have an array:
data=[15 6;85 54;90 4;56 87;37 15;24 65]
% my input
I want to obtain the result that show combinations of rows for the above array, which would be:
15 6 15 6 15 6
85 54 85 54 85 54
90 4 90 4 90 4
56 87 56 87 24 65
37 15 24 65 56 87
24 65 37 15 37 15
And goes on until every row is in all available positions.
I am looking forward to your helps. Thanks a lot!
  1 comentario
Rik
Rik el 9 de Dic. de 2020
Comment posted as flag by Anh Nguyen:
I have found another answer that gives a more clear output and suits my needs.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 4 de Dic. de 2020
result = permute(reshape( data(perms(1:size(data,1)).',:).', size(data,2), size(data,1), []), [2 1 3]);

Más respuestas (0)

Categorías

Más información sobre Cell Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by