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

MathGroup Archive 2010

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

Search the Archive

Re: List Manipulation: Conditionally changing y value

  • To: mathgroup at smc.vnet.net
  • Subject: [mg109015] Re: List Manipulation: Conditionally changing y value
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Sat, 10 Apr 2010 06:54:24 -0400 (EDT)

n=5;

x=RandomReal[{0,1}, n];

y=RandomReal[{0,1}, n];

pts=Thread[{x,y}];

{a,b}={.25,.75};

filtered1=If[a<#[[1]]<b,{1,0}#,#]&/@pts

or

filtered2={1,If[a<#[[1]]<b,0,1]}#&/@pts

or

filtered3={1,1-Boole[a<#[[1]]<b]}#&/@pts

filtered1==filtered2==filtered3

True


Bob Hanlon

---- Charles Koehler <cjkphd at 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



  • Prev by Date: Re: Using numbers close to to zero in Mathematica version 6
  • Next by Date: Re: Plot and advanced filling
  • Previous by thread: Re: How do you get Mathematica to evaluate "Floor" to give a number?
  • Next by thread: Formatting a symbol without evaluating it