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

Home » Public Forums » archive » Build 2D array from loops
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Build 2D array from loops [message #92754 is a reply to message #92744] Thu, 25 February 2016 02:44 Go to previous message
Matt G is currently offline  Matt G
Messages: 4
Registered: February 2016
Junior Member
On Monday, February 22, 2016 at 2:30:18 PM UTC, greg...@googlemail.com wrote:
> On Monday, February 22, 2016 at 2:08:39 PM UTC+1, Matt G wrote:
>> Hi, new to IDL so please forgive if very simple request.
>>
>> I'm trying to build an array where the values stored are in two columns: one with the values of i in my FOR loop, and the other the output of that FOR loop. To make it more complicated, within my FOR loop is an IF condition that skips over bad data.
>>
>> How do I structure this code so that the array is built from the output of my loops?
>>
>> Cheers
>
> It's often possible to work without loops in IDL. I'd do it something like this:
>
> IDL> i=indgen(10)
> IDL> a=i^2 ;replace with your expression
> IDL> b=transpose([[i],[a]]) ;combine into two column array
> IDL> b
> 0 0
> 1 1
> 2 4
> 3 9
> 4 16
> 5 25
> 6 36
> 7 49
> 8 64
> 9 81
>
> Use the where() function to filter out your bad values, e.g.
>
> IDL> q=where(a lt 50) ;keep only values where a<50
> IDL> b[*,q]
> 0 0
> 1 1
> 2 4
> 3 9
> 4 16
> 5 25
> 6 36
> 7 49
>
> cheers,
> Greg

Couldn't work out how to avoid a loop completely (it's quite a lengthy process for the data) but managed to sort out my issue from your advice.

Thanks a bunch!
Matt
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Multi-Threading - IDL_IDLBridge
Next Topic: Writting intoFile

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

Current Time: Wed Oct 08 17:54:57 PDT 2025

Total time taken to generate the page: 0.00438 seconds