- #1
jf22901
- 55
- 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.
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
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.
Code:
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: