X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 21 Sep 2007 01:32 AM by  anon
how to use a one elements array as single value?
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
21 Sep 2007 01:32 AM
    Hello, I have probably a stupid problem. I have a variable define as one-elemnt array (eg. fltarr(1)) and I need to use the value as simple float. what I have to do? cheers

    Deleted User



    New Member


    Posts:
    New Member


    --
    21 Sep 2007 01:32 AM
    In IDL documentation we call this "single value" a "scalar". Sometimes you do not have to do anything. I am not 100% sure and I am not taking the time to test this right now, but I think the vast majority of IDL functions can treat 1-element arrays the same way they treat scalars. Nevertheless, to be perfectly safe, you can always use the syntax: myOneElementFloatArray[0] Here are two examples where knowing about this syntax can be important: The very important filter function call "myTargetIndex = WHERE(...)" and the very important widget-handling procedure call "WIDGET_CONTROL, myTextWidget, GET_VALUE=text" both always return arrays, even when they have only one value to return. In this case the programmer needs to remember to always address that one value with the syntax "myTargetIndex[0]" resp. "text[0]". Best of luck, James
    You are not authorized to post a reply.