0

I am trying to calculate correlations for chosen intervals and then save the calculated correlations into an array to save them. But I was not succesful to safe the results after every iterration.

My testing code:

x=[1,2,3,1,6,7,11,9]
y=[1,6,7,8,1,3,2,1]
d = INTarr(n_elements(x))
e = INTarr(n_elements(x))
 for j=0, 3 do begin
  
  for i=0, n_elements(x)-1 do begin
    if x[i] gt 3*j and x[i] lt 3*(j+1) then d[i]=x[i] else d[i]=0 ;
   endfor

   for i=0, n_elements(x)-1 do begin
    if y[i] gt 3*j and y[i] lt 3*(j+1) then e[i]=y[i] else e[i]=0
   endfor
  c = INTarr(4)
  kor=correlate(d,e)
  c[j]=kor
 endfor
end

if I print "kor" inside the j-cycle I get the correct answer. But only the last iterration is saved after in the end. I tried to create a new array and rewrite its each component everytime the correlation coefficient is calculated for each cycle but i want for c to remember previous cycles results. I have no idea how to do that, any suggestion how to store meta-data please?

I would like to get to c = [c[j=0], c[j=1], c[j=2], c[j=3]]

mgalloy
  • 2,356
  • 1
  • 12
  • 10
Leif
  • 187
  • 1
  • 2
  • 11

1 Answers1

1

Move the creation of c outside your for loop.

mgalloy
  • 2,356
  • 1
  • 12
  • 10