Search code examples
loopsfor-loopidl-programming-language

How to save the results of loops-IDL


Change=[[N_elements(Change92_2001)],N_elements(Change92_2006),N_elements(Change92_2010)]
T=3
  FOR i=0,T-1 DO BEGIN
   area=Change[i]*900
   print,area
   help,area
 ENDFOR

I am trying to write a basic loop that will look at the number of pixels within certain images and then calculate the area of change within each image. How do I save the results of the loop into a new array?


Solution

  • Make area an array:

    area = fltarr(t)
    for i = 0, t - 1 do begin
      area[i] = change[i] * 900
    endfor
    

    And, of course, in this case the easiest way would be to just do:

    area = change * 900