-1

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

user40871
  • 9
  • 1
  • 2
  • What kind of rearrangement did you have in mind? In any event, you could work with the matrix's Transpose[] if need be. – J. M.'s missing motivation Jun 09 '16 at 10:16
  • 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. – user40871 Jun 09 '16 at 10:20
  • 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. – J. M.'s missing motivation Jun 09 '16 at 10:24
  • 7
    In general: http://mathematica.stackexchange.com/q/3069/5478 – Kuba Jun 09 '16 at 10:33
  • With respect to what you want to do, this is already answered in the question Kuba is referring to. See the "swap columns" part – Lukas Jun 09 '16 at 10:39

2 Answers2

5

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]]
Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
0

Hope the following code could help you:

ord={1,3,5,9,11}
Extract[mat,ord]~Join~Delete[mat,ord]
Wjx
  • 9,558
  • 1
  • 34
  • 70