Creating permutations from rows of a matrix
Afficher commentaires plus anciens
I have a matrix
X=[2-i 3+4i 5+7i; 7+8i 4-9i 7+9i; 2+i 4+8i 3-9i]
I would like to generate the following matrix (P) from X. Matrix P has six rows in total (3!), where by each row is composed of all the rows in X combined in a different order.
P=[2.0000 + 1.0000i 4.0000 + 8.0000i 3.0000 - 9.0000i 7.0000 + 8.0000i 4.0000 - 9.0000i 7.0000 + 9.0000i
2.0000 + 1.0000i 4.0000 + 8.0000i 3.0000 - 9.0000i 2.0000 - 1.0000i 3.0000 + 4.0000i 5.0000 + 7.0000i
7.0000 + 8.0000i 4.0000 - 9.0000i 7.0000 + 9.0000i 2.0000 + 1.0000i 4.0000 + 8.0000i 3.0000 - 9.0000i
7.0000 + 8.0000i 4.0000 - 9.0000i 7.0000 + 9.0000i 2.0000 - 1.0000i 3.0000 + 4.0000i 5.0000 + 7.0000i
2.0000 - 1.0000i 3.0000 + 4.0000i 5.0000 + 7.0000i 2.0000 + 1.0000i 4.0000 + 8.0000i 3.0000 - 9.0000i
2.0000 - 1.0000i 3.0000 + 4.0000i 5.0000 + 7.0000i 7.0000 + 8.0000i 4.0000 - 9.0000i 7.0000 + 9.0000i
Columns 7 through 9
2.0000 - 1.0000i 3.0000 + 4.0000i 5.0000 + 7.0000i
7.0000 + 8.0000i 4.0000 - 9.0000i 7.0000 + 9.0000i
2.0000 - 1.0000i 3.0000 + 4.0000i 5.0000 + 7.0000i
2.0000 + 1.0000i 4.0000 + 8.0000i 3.0000 - 9.0000i
7.0000 + 8.0000i 4.0000 - 9.0000i 7.0000 + 9.0000i
2.0000 + 1.0000i 4.0000 + 8.0000i 3.0000 - 9.0000i]
2 commentaires
Walter Roberson
le 18 Juil 2020
You happen to be using a square matrix, X -- it is 3 x 3. Will your input X always be 3 x 3? Will your input X always be square? If X were 3 x 4 what would the expected output be like?
You can write it up like a prototype: if the original matrix were [11 12 13 14; 21 22 23 24; 31 32 33 34] then what would the expected output be?
Roland Niwareeba
le 18 Juil 2020
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 18 Juil 2020
Modifié(e) : Walter Roberson
le 18 Juil 2020
idx = reshape(nchoosek(1:size(X,1),2).',[],1);
P = X(idx,:);
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!