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 #92744 is a reply to message #92743] Mon, 22 February 2016 06:30 Go to previous messageGo to previous message
greg.addr is currently offline  greg.addr
Messages: 160
Registered: May 2007
Senior Member
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
[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 19:28:42 PDT 2025

Total time taken to generate the page: 0.00442 seconds