MathGroup Archive 2011

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

Search the Archive

Re: With Nearest

  • To: mathgroup at smc.vnet.net
  • Subject: [mg121114] Re: With Nearest
  • From: Ray Koopman <koopman at sfu.ca>
  • Date: Mon, 29 Aug 2011 03:47:19 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <j3anc3$hdo$1@smc.vnet.net>

On Aug 27, 5:19 am, graser <gra... at gmail.com> wrote:
> Dear Mathematica group,
> I have a simple question for you.
> Let's say there is an array or matrix like
>
> AA = {{1.3, 1.5}, {21.5, 23.6}, {10, 19}};
>
> If I want to extract a list whose second element is close to 20,
> How can I do it with Nearest function?
> Or is there any other method possible?
> ( In this case, the answer should be {10, 19} )
>
> Thanks!

If AA is long then

   AA[[ Ordering[ Abs[ AA[[All,2]] - 20 ], 1] [[1]] ]]
or
   Extract[ AA, Ordering[ Abs[ AA[[All,2]] - 20 ], 1] ]

will be much faster than anything using Nearest.




  • Prev by Date: Plot Manipulate Table
  • Next by Date: NDSolve solution does not fulfill boundary condition ??
  • Previous by thread: Re: With Nearest
  • Next by thread: Re: With Nearest