How do I rearrange the columns of a matrix? I really have o idea how to do this. Thankfs for any suggestions!

  • $\begingroup$ What kind of rearrangement did you have in mind? In any event, you could work with the matrix's Transpose[] if need be. $\endgroup$ – J. M. is in limbo Jun 9 '16 at 10:16
  • $\begingroup$ THanks! I was thinking of something like choosing columns 4,5,7,8,11 in a matrix with more than 11 columns and putting them at the beginning of the matrix. $\endgroup$ – user40871 Jun 9 '16 at 10:20
  • $\begingroup$ You should have mentioned that in your question to begin with; but, look up Extract[] and Delete[]. Or, multiply your matrix with an appropriately permuted identity matrix. $\endgroup$ – J. M. is in limbo Jun 9 '16 at 10:24
  • 7
    $\begingroup$ In general: mathematica.stackexchange.com/q/3069/5478 $\endgroup$ – Kuba Jun 9 '16 at 10:33
  • $\begingroup$ With respect to what you want to do, this is already answered in the question Kuba is referring to. See the "swap columns" part $\endgroup$ – Lukas Jun 9 '16 at 10:39

Use Part.

E.g. to exchange row 2 and 3 while also exchanging column 1 and 2 in a 3x3 matrix,

rowOrd = {1,3,2};
colOrd = {2,1,3};
mat[[rowOrd, colOrd]]

Hope the following code could help you:


Not the answer you're looking for? Browse other questions tagged or ask your own question.