MathGroup Archive 2006

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

Search the Archive

Re: For Loop problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg65603] Re: [mg65595] For Loop problem
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Tue, 11 Apr 2006 04:04:09 -0400 (EDT)
  • Reply-to: hanlonr at cox.net
  • Sender: owner-wri-mathgroup at wolfram.com

y=Range[0,5000,1000]

{0,1000,2000,3000,4000,5000}

y=If[#>2048,#-2048,#+2048]&/@y

{2048,3048,4048,952,1952,2952}


Bob Hanlon

> 
> From: Rob <rob at piovere.com>
To: mathgroup at smc.vnet.net
> Subject: [mg65603] [mg65595] For Loop problem
> 
> I've got to manipulate some signed 12bit integer numbers from a file and
> apparently Mathematica only handles 8 and 16 bit signed numbers
> (probably for a very good reason). So I bring them in as 16 bits (and
> they're stored that way with a leading zero nibble) and then I have to
> do the following to make sense of them.  I really don't know why this
> code works but it does.
> 
> For[i = 1, i < Length[y], i++, If[y[[i]] > 2048, y[[i]] =
>      y[[i]] - 2048, y[[i]] = y[[i]] + 2048]];
> 
> So to my question: once again I had to resort to a For loop to pull this
> off and I know this is a no-no.  But I'm so clueless about Mathematica
> that I've never come up with a more sophisticated method after a year or
> so of thinking about it. Can someone help (as they usually can)?
> 
> Thanks, Rob
> 
> 


  • Prev by Date: Re: To apply a function to a List
  • Next by Date: Re: For Loop problem
  • Previous by thread: Re: For Loop problem
  • Next by thread: Re: For Loop problem