Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: Sorting Rows of a Matrix

  • To: mathgroup at smc.vnet.net
  • Subject: [mg65104] Re: Sorting Rows of a Matrix
  • From: "J Siehler" <jsiehler at gmail.com>
  • Date: Wed, 15 Mar 2006 06:28:15 -0500 (EST)
  • References: <dv69a6$o6l$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Sort allows passing a comparison function as the second argument.
Here's a 12x4 random matrix sorted by the second column.

m = Table[Random[Integer, 30], {12}, {4}]
m // MatrixForm
Sort[m, #1[[2]] = #2[[2]] &] // MatrixForm

If you do this frequently you might define

sortMatrix[m_,key_]:=Sort[m, #1[[key]] = #2[[key]] &]


  • Prev by Date: Multiple Selections in Notebook
  • Next by Date: Re: Sorting Rows of a Matrix
  • Previous by thread: Re: Sorting Rows of a Matrix
  • Next by thread: Re: Sorting Rows of a Matrix