Re: help array subscripting [message #49100] |
Mon, 26 June 2006 09:38 |
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 #49110 is a reply to message #49109] |
Sat, 24 June 2006 13:54  |
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  |
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
|
|
|