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

MathGroup Archive 2009

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

Search the Archive

Re: Replacing Values Close to One

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105296] Re: Replacing Values Close to One
  • From: Peter Breitfeld <phbrf at t-online.de>
  • Date: Thu, 26 Nov 2009 06:15:16 -0500 (EST)
  • References: <hekug7$921$1@smc.vnet.net>

Gregory Lypny wrote:

> Hello everyone,
>
> Is there a replacement rule that I can apply to
>
> 	{-8, .7, 0, 1.003}  /.  [What goes here?] -> 1
>
> to replace values that are close to 1, like 1.003, by 1?
>
> Regards,
>
> 	Gregory
>

I would define a function like this one:

SetAttributes[nearOne]={Listable};
nearOne[x_]:=If[0.995<Abs[x]<1.005,1,x]

then:
In=	{-8, .7, 0, 1.003}//nearOne
Out={-8, 0.7, 0, 1}


-- 
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de


  • Prev by Date: Re: Replacing Values Close to One
  • Next by Date: Re: Replacing Values Close to One
  • Previous by thread: Re: Re: Re: Replacing Values Close to One
  • Next by thread: Re: Replacing Values Close to One