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

Home » Public Forums » archive » array concatenation in 2-D
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
array concatenation in 2-D [message #59630] Fri, 04 April 2008 11:38 Go to next message
elwood is currently offline  elwood
Messages: 23
Registered: February 2007
Junior Member
I have a loop which calculates two variables x[i] and y[i]

At each iteration of the loop I calculate
x and y
And I'd like to concatenate x and y into a 2 column, unknown numbers
of rows
output array.
I'd like to dynamically grow the output array at each interation.

For example:
x=1 y=5 on first iteration
x=2, y=6 on 2nd iteration
I want an output array that looks like the below:

1 5
2 6

How do i achieve this without knowing the array size??


Tx!
-Elisha
Re: array concatenation in 2-D [message #59725 is a reply to message #59630] Wed, 09 April 2008 08:44 Go to previous message
Jean H. is currently offline  Jean H.
Messages: 472
Registered: July 2006
Senior Member
elwood wrote:
> On Apr 4, 2:31 pm, Jean H <jghas...@DELTHIS.ucalgary.ANDTHIS.ca>
> wrote:
>> elwood wrote:
>>> I have a loop which calculates two variables x[i] and y[i]
>>> At each iteration of the loop I calculate
>>> x and y
>>> And I'd like to concatenate x and y into a 2 column, unknown numbers
>>> of rows
>>> output array.

> Alas, this is a form of concatenation, but it does not produce
> the required results.
> I need to concatenate by COLUMN, not row.
> If I code the concatenation you show, it produces:
> column 1:
> 1 2
> 3 4
> 5 6
>
> Whereas I need it to paste the columns together such that I
> get
> 1 3 5
> 2 4 6
>
> To be specific, each iteration of the loop
> I calculate new values of x and y
> I want to do the following, but using concatenation
> outputarry[0,0]=x1
> outputarry[1,0]=y1
>
> next iteration
> outputarry[0,1]=x2
> outputarry[1,1]=y2
>
> to get a final array where x values are in column 0
> y values are in column 1

your initial and second post are opposite! ... be sure to understand the
row/column system used in IDL (see
http://idlastro.gsfc.nasa.gov/idl_html_help/Columns_Rows_and _Array_Majority.html
)

Anyways, you can do concatenation, according to your 2nd post like that:
a = [[1,3],[2,4]]
a= [a,transpose([5,6])]
IDL> print,a
1 3 5
2 4 6

Jean
Re: array concatenation in 2-D [message #59748 is a reply to message #59630] Tue, 08 April 2008 23:37 Go to previous message
Spon is currently offline  Spon
Messages: 178
Registered: September 2007
Senior Member
On Apr 9, 2:19 am, elwood <epolo...@uwsp.edu> wrote:
> Alas, this is a form of concatenation, but it does not produce
> the required results.
> I need to concatenate by COLUMN, not row.
> If I code the concatenation you show, it produces:
> column 1:
> 1 2
> 3 4
> 5 6
>
> Whereas I need it to paste the columns together such that I
> get
> 1 3 5
> 2 4 6
>
> To be specific, each iteration of the loop
> I calculate new values of x and y
> I want to do the following, but using concatenation
> outputarry[0,0]=x1
> outputarry[1,0]=y1
>
> next iteration
> outputarry[0,1]=x2
> outputarry[1,1]=y2
>
> to get a final array where x values are in column 0
> y values are in column 1

You're almost where you want to be :-)
You can use TRANSPOSE your array to get the desired effect. It does
make concatenating a little bit more tricky, but with the help of
these two tutorials:

http://www.dfanning.com/tips/array_concatenation.html
http://www.dfanning.com/tips/rebin_magic.html

you'll be flying through it before you know it!
Alternatively you can let your concatenation happen row-by-row until
you're done, and then just transpose at the end, if that's simpler.

Good luck,

Chris
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: aster 1A -
Next Topic: Re: fastest way to find the first non-zero value in an array

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

Current Time: Wed Oct 08 19:13:26 PDT 2025

Total time taken to generate the page: 0.01030 seconds