X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 05 Jan 2018 01:15 PM by  Jim Uba
How to select and operate on a subset of array elements?
 0 Replies
Sort:
You are not authorized to post a reply.
Author Messages

Jim Uba



New Member


Posts:81
New Member


--
05 Jan 2018 01:15 PM
    IDL USER QUESTION::

    "I have an IDL problem that I haven’t been able to solve and was hoping you might be able to point me in the right direction. I have a raster that I’ve read into an array and I want to perform an operation only where there aren’t the no data values of -32767. I thought I could use the if statements but they don’t work on arrays obviously. Is there an array expression equivalent that will allow me to do this?"

    ANSWER:

    Here is example code that illustrates how target value elements in an array can be detected and manipulated without looping:

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ; create short int array data
    data = fix( randomu(seed, 10, 10, /long) )
    help, data

    ; select array index locations to assign bad value
    ibad = fix( randomu(seed, 20) * 100 )
    help, ibad

    badval = -32767
    data[ibad] = badval ; assign elements bad data
    print, data

    ; get array index locations with good data
    igood = where( data NE badval )

    ; if one or more array element indexes are returned
    ; (not a scalar -1) then manipulate those array elements
    if igood[0] NE -1 then $
    data[igood] = 0 ; manipulate good data
    print
    print, data
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    For additional information about using arrays in IDL see also:

    https://www.harrisgeospatial.com/docs/Arrays.html
    https://www.harrisgeospatial.com/docs/WHERE.html

    You are not authorized to post a reply.