Prev: norm Function with FindRoot
Next: 3D interpolating
From: dh on 12 Apr 2010 06:50 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(a)metrohm.com> Internet:<http://www.metrohm.com>
From: Armand Tamzarian on 12 Apr 2010 23:00 On Apr 9, 2:31 am, "Charles Koehler" <cjk...(a)wi.rr.com> 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 Try using a rule replacement. e.g. a=3;b=13; Table[{RandomInteger[{0, 20}], RandomReal[{1, 4}]}, {20}] /. {x_, y_} /; a < x < b :> {x, 0}
|
Pages: 1 Prev: norm Function with FindRoot Next: 3D interpolating |