MATLAB: Creating permutations from rows of a matrix

combinationsmatricespermutations

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]

Best Answer

This question is almost like what you ask in this thread
Only the formating of the input is different (in one case you split the sequences in different variables, in other case they are grouped as rows of an array).
The difference is not big enough the create 2 separate threads IMO, and you better think finding solution as combining of separate smaller steps if smaller problem.
% Input
X = [2-i 3+4i 5+7i; 7+8i 4-9i 7+9i; 2+i 4+8i 3-9i];
P = cell2mat(perms(num2cell(X,2)))
Here
num2cell(X,2)
and
{X1 X2 X3} % on the answer of other question
return the same cell for two different input storage schemes. You might reduce your question to this simply formatage.