MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: sorting a Matrix



Peter Klamser wrote:

> with Sort[{a,f,e,s}] I can sort a Vector (a List). How can I sort a
> Matrix??
> 
> In the Help I can find the Information: Sort[{33,76,2,6,17},#1>#2&]
> 
> For a Matrix I think it should work like this:
> Sort[{33,76,2,6,17},#1[[#5,#3]]>#2[[#4,#3]]&]
> 
> where #3 is the column to be sorted for, and #5 and #4 are the different
> Vectors in the Matrix.

Peter:

m={{6,0,4},{5,8,5},{2,9,7}}

Sort by column 2:

Sort[m, #1[[2]]>= #2[[2]]&]

{{2,9,7},{5,8,5},{6,0,4}}

-- 
Allan Hayes
Training and Consulting
Leicester, UK
hay@haystack.demon.co.uk
http://www.haystack.demon.co.uk
voice: +44 (0)116 271 4198
fax: +44 (0)116 271 8642




  • Prev by Date: Re: Semi-Log for X-axis
  • Next by Date: RE: Tan,Cot,Csc,etc
  • Prev by thread: Re: sorting a Matrix
  • Next by thread: RE: test positive