Re: same question with correct reply Email address [message #28398] |
Wed, 05 December 2001 15:37 |
meron
Messages: 51 Registered: July 1995
|
Member |
|
|
In article <3C0EA820.54127170@hotmail.com>, Frederic Raison <frederic_raison@hotmail.com> writes:
>
> Hi!
>
> Sorry about my wrong email address. ITt was hotmail.com and not
> hotmai.com..
>
> Is there anybody who could tell me if there is an IDL instruction, like
> in Matlab, able to convert a string into the name of a variable and
> vice-versa? I mean if I have defined :
>
> a=1
> b=2
> list=['a','b']
>
>
> I would like to write:
>
> print,somme_instruction(list[0])
>
> and to get:
>
> 1
>
You can use EXECUTE. for example
IDL> a = 1
IDL> b = 2
IDL> c = 3
IDL> dum = execute('res=exp(' + list[0] + ')')
IDL> print, res
2.71828
IDL> dum = execute('res=exp(' + list[2] + ')')
IDL> print, res
20.0855
It is useful at times, when you need the flexibility to build up an
appropriate commend within a routine.
Mati Meron | "When you argue with a fool,
meron@cars.uchicago.edu | chances are he is doing just the same"
|
|
|