Access array elements with String [message #61367] |
Mon, 14 July 2008 08:16 |
humanumbrella
Messages: 52 Registered: June 2008
|
Member |
|
|
Hello all,
Another issue - perhaps one of you has encountered this before. It's
sort of a neat problem. I'm attempting to build array subscripts on
the fly based on user input. IE the number of static/variable elements
is changing, which allows the user to pick different axes to plot.
Nevermind all that.
Anyway, let's say a user wants a particular axis to be variable. In
this case, the dataset array where I'm attempting to pull values from
would contain a *, to get all these elements. Unfortunately, I do not
know in advance which dimension of the array I will be using, so I am
attempting to build the subscript based on a string.
This was my original thought:
a = dindgen(5,5,5)
b = ['3','3','3']
print, a[b]
but this just returns a[3], a[3], a[3]
So, I figured I'd do it this way:
c = '3'
print, a[c,c,c] -- This works!
Now for the gold,
d = '*'
print, a[c,c,d] -- error - can't convert string-> long
so I get an idea-- maybe I'll just use the ascii value for the
asterisk.
d = String(42b)
print, a[c,d,d] -- error - can't convert string-> long
Any thoughts ?
Thanks in advance
--Justin
|
|
|