Creating permutations from rows of a matrix
Show older comments
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 Comments
Walter Roberson
on 18 Jul 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
on 18 Jul 2020
Accepted Answer
More Answers (1)
Walter Roberson
on 18 Jul 2020
Edited: Walter Roberson
on 18 Jul 2020
idx = reshape(nchoosek(1:size(X,1),2).',[],1);
P = X(idx,:);
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!