Re: Q: Indexing arrays with variable # dimensions [message #4803] |
Thu, 10 August 1995 00:00 |
rivers
Messages: 228 Registered: March 1991
|
Senior Member |
|
|
In article <40civl$neh@korfu.igd.fhg.de>, Tim Purschke <purschke> writes:
> i want to index an array with a number of dimensions that is not known
> until runtime.
> Creation of array:
> a = intarr(dimsize^dimnumber)
> dimidx = intarr(dimnumber) + dimsize
> a = reform(a, dimidx)
>
> Now i want to set an element of a to a certain value.
> eg. a(3,2,4,3) = 7 (for dimnumber = 4)
>
> how can i store this index list to make the asignment work?
> i've tried idx=[3,2,4,3] & a(idx) =7 but this of course does not work.
IDL lets one address multi-dimensional arrays as single-dimension arrays.
Thus, I think this is right:
idx = 3*dimsize^3 + 4*dimsize^2 + 2*dimsize + 3
a(idx) = 7
This can obviously be generalized if your array is not a hypercube, i.e. all of
the dimensions are not the same.
____________________________________________________________
Mark Rivers (312) 702-2279 (office)
CARS (312) 702-9951 (secretary)
Univ. of Chicago (312) 702-5454 (FAX)
5640 S. Ellis Ave. (708) 922-0499 (home)
Chicago, IL 60637 rivers@cars3.uchicago.edu (Internet)
|
|
|