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

Home » Public Forums » archive » Re: help array subscripting
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: help array subscripting [message #49100] Mon, 26 June 2006 09:38
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
On Sat, 24 Jun 2006 11:21:48 -0700, pimpk24 wrote:

> Hello all,
>
> I am looking for a more efficent way to subscript various data arrays to a
> time/index array
>
> Say I have data arrays : [x], [y], [z],
>
> and I have time arrays : [1pm] , [2pm], [3pm] , [4pm] etc......
>
> Right now I am simply doing this by typing:
>
> x_1pm = x[1pm]
> x_2pm=x[2pm]
>
> y_1pm=y[1pm] etc............
>
> This is very long and tedious, so I imagine (hope) there must be a better
> way.

You can either use higher-dimensional arrays (if 1pm, 2pm, 3pm
etc. all have the same length), and index them all at once, like:

times=[ [1_pm], [2_pm], [3_pm] ]
xt=x[times]
yt=y[times]

or, if they are of different length, use an array of pointers, ala:

times=ptrarr(n_times)
times[0]=ptr_new(...) ;; fill in the times pointer array

for i=0,n_elements(times)-1 do begin
xt=x[*times[i]]
yt=y[*times[i]]
;; do something with xt, yt
endfor

JD
Re: help array subscripting [message #49108 is a reply to message #49100] Sat, 24 June 2006 14:36 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
pimpk24@hotmail.com writes:

> it is such a repetitive excercise because there are many x,y,z etc..
> and many time arrays
> Usually loops are good for repetitive processes but I dont see how that
> would work in this case.

Me, either. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: help array subscripting [message #49109 is a reply to message #49108] Sat, 24 June 2006 14:32 Go to previous message
greg michael is currently offline  greg michael
Messages: 163
Registered: January 2006
Senior Member
1pm is a vector? Why? You have to explain more there...

Greg
Re: help array subscripting [message #49110 is a reply to message #49109] Sat, 24 June 2006 13:54 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
pimpk24@hotmail.com writes:

> I am looking for a more efficent way to subscript various data arrays
> to a time/index array
>
> Say I have data arrays : [x], [y], [z],
>
> and I have time arrays : [1pm] , [2pm], [3pm] , [4pm] etc......
>
> Right now I am simply doing this by typing:
>
> x_1pm = x[1pm]
> x_2pm=x[2pm]
>
> y_1pm=y[1pm] etc............
>
> This is very long and tedious, so I imagine (hope) there must be a
> better way.

Huh? Tedious!? I don't get it.

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: help array subscripting [message #49111 is a reply to message #49110] Sat, 24 June 2006 12:18 Go to previous message
greg michael is currently offline  greg michael
Messages: 163
Registered: January 2006
Senior Member
I'm confused by your notation (I suspect you may also be). I'd guess
you want to write something like:

x=[.1,.4,.2,1.2]

with similar expressions to define your y and z arrays. These represent
values for certain times, which could be expressed as:

time=['1pm','2pm','3pm','4pm']

and you would access individual values like this:

i=0
print,'The value of x at '+time[i]+' was '+strtrim(x[i],2)

changing i to select your time.

There are better ways to represent the time, but this should at least
solve the indexing problem.

regards,
Greg
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Help with Roi syntax!
Next Topic: Re: what IDL version should be installed on a 64-bit redhat linux, SGI (MIPS) machine ?

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

Current Time: Wed Oct 08 13:36:30 PDT 2025

Total time taken to generate the page: 0.00759 seconds