Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: Sorting 3 points

  • To: mathgroup at smc.vnet.net
  • Subject: [mg87980] Re: Sorting 3 points
  • From: Szabolcs Horvát <szhorvat at gmail.com>
  • Date: Mon, 21 Apr 2008 06:40:07 -0400 (EDT)
  • Organization: University of Bergen
  • References: <fuhfa6$ibk$1@smc.vnet.net>

carlos at colorado.edu wrote:
> Simple question, but documentation is no help.
> I have three coordinate triplets:
> 
>  P1={x1,y1,z1}      P2={x2,y2,z2}      P3={x3,y3,z3}
> 
> where all entries are numeric. I wont to sort them into
> 
>  P1s={xs1,ys1,zs1} P2s={xs2,ys2,zs2} P3s={xs3,ys3,zs3}
> 
> so that zs3>=zs2>=zs1, with one command
> 
>    {P1s,P2s,P3s}=Sort[{P1,P2,P3}, Ordering Function]
> 
> Is that possible and if so, which Ordering Function
> should be used?  Thanks.


Well, this is pretty simple if you read what an ordering function is ...

Sort[list, Last[#1] < Last[#2] &]

(Or if you have Mathematica 6, just use SortBy[list, Last])

Perhaps the missing piece was constructing anonymous functions?  Read 
the doc page of Function for an explanation (#1, #2 are the first and 
second arguments of the function).


  • Prev by Date: Re: function not evaluating question tia sal2
  • Next by Date: Re: problem accessing notebooks
  • Previous by thread: Re: Sorting 3 points
  • Next by thread: Re: Sorting 3 points