Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Say I have matrix original

how to sort on row by row basis to get:

sorted

share|improve this question
5  
Let mat be your matrix, then Sort /@ mat. –  VLC Nov 15 '12 at 13:05
    
Hi @VLC thanks. Nice and simple, but can'd find the accept button? :) –  sebastian c. Nov 15 '12 at 13:09

1 Answer 1

up vote 3 down vote accepted

Sort on row by row basis:

mat = {{1, 3, 2, 4}, {4, 3, 2, 1}, {3, 2, 4, 1}, {1, 2, 4, 3}};

matrix

Sort /@ mat

sorted matrix

Sort on column by column basis:

mat2 = {{4, 3, 1, 4}, {2, 4, 3, 2}, {1, 1, 2, 3}, {3, 2, 4, 1}};

matrix

Transpose[Sort /@ Transpose[mat2]]

sorted matrix

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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