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

Home » Public Forums » archive » subscripting arrays with dim > 1
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
subscripting arrays with dim > 1 [message #12707] Fri, 28 August 1998 00:00 Go to previous message
fireman is currently offline  fireman
Messages: 49
Registered: August 1991
Member
I'd like to reference an array with a variable containing a subscript for
each dimension, passing the subscripts as an array. For instance:

IDL> array = indgen(5,5)
IDL> print,array
0 1 2 3 4
5 6 7 8 9
10 11 12 13 14
15 16 17 18 19
20 21 22 23 24
IDL> print,array[0,4]
20

But I can't seem to reference each dimension. Instead, the subscript array
is passed as two instances of a single subscript:

IDL> index=[0,4]
IDL> print,array[index]
0 4

I can of course calculate a single index, but it seems a bit clunky:

IDL> s=size(array)
IDL> print,s
2 5 5 2 25
IDL> print,array[index(0)*s(1)+index(1)*s(2)]
20
- or -
IDL> print,array[long(total(s(1:s(0))*index))]
20

Is there a better way?
Gwyn

--
__.
/ | , , , , , ,_ Gwyn F. Fireman
(__/|/(_(_)(_/|/| |_/ General Sciences Corporation
/| /| Gwyn.Fireman@gsfc.nasa.gov MODIS Characterization Supp. Team
(_/ (_/ 301-352-2118
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Re: allocating data to different array on each loop step
Next Topic: Re: Quickly Erasing lines on direct graphics images

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

Current Time: Wed Oct 08 18:57:26 PDT 2025

Total time taken to generate the page: 0.00505 seconds