Combinations of the rows of matrices
Mostrar comentarios más antiguos
I am trying to find all possible combinations of matrices a1-a3.
a1 = [1 2 3; 4 5 6];
a2 = [7 8; 9 10];
a3 = [11; 12];
I want the resulting matrix.
[1 2 3 7 8 11;
1 2 3 9 10 11;
1 2 3 7 8 12;
1 2 3 9 10 12;
4 5 6 7 8 11;
4 5 6 9 10 11;
4 5 6 7 8 12;
4 5 6 9 10 12]
Respuestas (1)
James Tursa
el 7 de Jul. de 2015
Editada: James Tursa
el 7 de Jul. de 2015
A slightly different order for the rows than you have listed, but contains the same content:
[X Y Z] = meshgrid(1:size(a1,1),1:size(a2,1),1:size(a3,1));
result = [a1(X(:),:) a2(Y(:),:) a3(Z(:),:)];
Categorías
Más información sobre Data Types en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!