MathGroup Archive 2010

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

Search the Archive

Re: List Manipulation: Conditionally changing y value when x value

  • To: mathgroup at smc.vnet.net
  • Subject: [mg109074] Re: List Manipulation: Conditionally changing y value when x value
  • From: dh <dh at metrohm.com>
  • Date: Mon, 12 Apr 2010 06:55:37 -0400 (EDT)
  • References: <hpml5b$9nk$1@smc.vnet.net>

On 09.04.2010 09:31, Charles Koehler wrote:
> Hello,
>
>
>
> If possible I could use a little help on this.
>
>
>
> I have a list of  x and y data and based on the value of x I would like to
> manipulate the value y.
>
> I joined the data using:
>
> pts=MapThread[{##1}&,{x,y}]
>
> I assumed that by testing the x value using #[[1]], I could change the value
> of y using #[[2]] as shown below.  If no manipulation was required based on
> the value of x, I would keep that point unchanged, but I'm definitely
> missing something.
>
>
>
> filtered=If[a<#[[1]]&<b,#[[2]]&=0],{#[[1]],#[[2]]}&,pts]
>
>
>
> a and b are the range of x values
>
>
>
>
>
> Any insight would be much appreciated.
>
>
>
> Thanks,
>
>
>
> Chuck Koehler
>
Hi Chuck,
I do not understand fully what you want, but lets try.
Getting x-y pairs can be done simpler by:
pts=Transpose[{x,y}]
Now assume you want to set y values belonging to x values outside [a,b] 
to zero, you would define an anonymous function and map it onto your 
points. The function checks if x is in range and returns the argument 
unchanged if so, otherwise it sets the y value to zero:
(If[a<=#[[1]]<=b,#,{#[[1]],0}])& /@ pts

cheers, Daniel



-- 

Daniel Huber
Metrohm Ltd.
Oberdorfstr. 68
CH-9100 Herisau
Tel. +41 71 353 8585, Fax +41 71 353 8907
E-Mail:<mailto:dh at metrohm.com>
Internet:<http://www.metrohm.com>



  • Prev by Date: Re: Retrieving orphaned code
  • Next by Date: Re: ShowGraph vs. GraphPlot
  • Previous by thread: .swf export and hyperlinking
  • Next by thread: Re: List Manipulation: Conditionally changing y value when x value