comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: idl array operations
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: idl array operations [message #47757] Wed, 01 March 2006 14:44
alex922@gmail.com is currently offline  alex922@gmail.com
Messages: 8
Registered: February 2006
Junior Member
Yes, this was my goal.

Thanks Craig!
Re: idl array operations [message #47764 is a reply to message #47757] Tue, 28 February 2006 22:50 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
mmeron@cars3.uchicago.edu writes:
> In article <1141168957.087822.106350@i39g2000cwa.googlegroups.com>, "alex922@gmail.com" <alex922@gmail.com> writes:
>> Hi,
>>
>> I'm pretty new to IDL and someone told me to avoid loops.
>>
>> I have the following problem. I have an array of elements whose values
>> range from 0 to 360, and I have to subtract a number if the value is
>> greater than 180.
...
> Taking your array as arr and the nuber to be subtracted as x, the line
> would be
> arr = arr - x*(arr gt 180)

Or, if you are trying to map longitude in the 0 to 360 range to the
-180 to 180 range, I often would use this:

LONGITUDE = ((LONGITUDE + 180) MOD 360) - 180

Craig


--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: idl array operations [message #47766 is a reply to message #47764] Tue, 28 February 2006 15:34 Go to previous message
mmeron is currently offline  mmeron
Messages: 44
Registered: October 2003
Member
In article <1141168957.087822.106350@i39g2000cwa.googlegroups.com>, "alex922@gmail.com" <alex922@gmail.com> writes:
> Hi,
>
> I'm pretty new to IDL and someone told me to avoid loops.
>
> I have the following problem. I have an array of elements whose values
> range from 0 to 360, and I have to subtract a number if the value is
> greater than 180.
>
> My initial reaction is to create a loop and use condition statements to
> perform the calculations.
>
> Is there a 'one liner' array operation which would allow me to do this
> without using loops?
>
> Thanks,
> Alex
>
Taking your array as arr and the nuber to be subtracted as x, the line
would be
arr = arr - x*(arr gt 180)

Mati Meron | "When you argue with a fool,
meron@cars.uchicago.edu | chances are he is doing just the same"
Re: idl array operations [message #47767 is a reply to message #47766] Tue, 28 February 2006 15:27 Go to previous message
alex922@gmail.com is currently offline  alex922@gmail.com
Messages: 8
Registered: February 2006
Junior Member
Thanks a bundle!
Re: idl array operations [message #47768 is a reply to message #47767] Tue, 28 February 2006 15:26 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
alex922@gmail.com wrote:
> Hi,
>
> I'm pretty new to IDL and someone told me to avoid loops.
>
> I have the following problem. I have an array of elements whose values
> range from 0 to 360, and I have to subtract a number if the value is
> greater than 180.
>
> My initial reaction is to create a loop and use condition statements to
> perform the calculations.
>
> Is there a 'one liner' array operation which would allow me to do this
> without using loops?

Dunno about a one-liner:

loc=where(data gt 180.0,count)
if (count gt 0) then data[loc]=data[loc]-number

There's probably a solution via HISTOGRAM, too. :o)

paulv


--
Paul van Delst
CIMSS @ NOAA/NCEP/EMC
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: problem with dual monitor setup
Next Topic: Help in Image Analysis

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:43:08 PDT 2025

Total time taken to generate the page: 0.00614 seconds