Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Replacing specific array elements in IDL

  1. Sep 1, 2011 #1
    Replacing specific array elements in IDL - solved!

    Hi

    I was just wondering if there was any way, other than using FOR loops, to replace specified elements of an array?

    For example, say A is a 1D array of 50 elements, each equal to 1.0. Is it possible to change say elements 0-9 and 30-49 to 5.0 other than the way shown below? I thought maybe I could use the REPLICATE_INPLACE function, but can't find a way of getting it to work. :grumpy:

    Code (Text):

    A = FLTARR(50)+1.0

    FOR i = 0, 9 DO BEGIN
        A(i) = 5.0
    ENDFOR

    FOR i = 30, 49 DO BEGIN
        A(i) = 5.0
    ENDFOR

    END
     
    The above method works fine, but there must be a way that doesn't involve loops, as I know loops slow IDL down.

    Many thanks
     
    Last edited: Sep 1, 2011
  2. jcsd
  3. Sep 1, 2011 #2
    Problem solved. I've realized I can simply type A[0:9]=5.0 etc. :biggrin:
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Replacing specific array elements in IDL
Loading...