-1

I am trying to save the results of loop in a new array, then plot them. But now I can only save the last value comes from the loop. How can I save all the results from the loop?

for j=1,200 do begin
  h = where(o eq j,ct3)
  if (ct3 ne 0) then begin
    mag = a1[h].imag
    bcg = min(mag)
    deltay = pqq[plu2[j]]
    bcg1 = float(bcg)
    u = where(bcg1*deltay ne 0)
    bcg2 = bcg1[u]
    deltay1 = deltay[u]
    print,deltay1,bcg2
    plot,bcg2,deltay1,psym=5
  endif 
endfor
mgalloy
  • 2,356
  • 1
  • 12
  • 10

1 Answers1

0

To store a variable number of values each time through your loop, I would use a list and then the toArray method when you want the final array to plot.

For example, at the beginning of your code create a list to store the results in:

deltay_list = list()

Then in your loop, add elements to your list:

deltay_list->add, deltay1, /extract

The EXTRACT keyword indicates that you should add the individual elements of deltay1, not add deltay as a single element of the list. When you want to plot, then do:

deltay_array = deltay_list->toArray()
obj_destroy, deltay_list
plot, deltay_array
mgalloy
  • 2,356
  • 1
  • 12
  • 10