[ncl-talk] regression with lag

Kevin Hallock hallock at ucar.edu
Mon Oct 2 17:44:33 MDT 2017


Hi,

I noticed in your code’s do-loop that you’re incrementing n independently of the loop.

If you modify the loop to include “print(n)”:
do n=0,nlagr-1
      n = n+1
      print(n)
      Regdata(:,:,n) =regline(x(0:Nend-n-yLag), P1(:,:,yLag+n:Nend))
end do ;

you can see that the only values of “n” used in the “Regdata(:,:,n) =…” line are (/1,3,5,7,9,11,13,15,17,19,21/), because n is being incremented by both the loop structure itself and the “n = n+1” line.

If this is intentional and you want your value of n to increase by 2 every loop iteration, you could cleanly write this by adding a third comma-separated value on the “do n=“ line, for example:
do n=0,nlagr-1,2
      print(n)
end do

Otherwise, you might want to try removing the “n = n+1” line and rerunning your script.

Regarding the subscript error you experienced, I believe that the final 21 value mentioned above is causing the error you’re seeing, as the third dimension of Regdata is “nlagr” elements long — 21 in this case, with valid indices ranging from 0 to 20, inclusive.

I hope this helps,
Kevin

> On Oct 2, 2017, at 8:25 AM, Sancta Vega <sanctavega at gmail.com> wrote:
> 
> according to this answer  https://www.ncl.ucar.edu/Support/talk_archives/2013/2968.html <https://www.ncl.ucar.edu/Support/talk_archives/2013/2968.html>
> 
> I need the 10 positive and negative lag regression  of my data x(time), P1(lat,lon,time) but I dont loop trough lat lon .
> 
> This is my code :
> 
> dim_s   = dimsizes(P1)  ;;; 
>  Nend = 5000 ; length of  x
>  nlagr= 21 ; +- 10 lag 
>   yLag = 10
> 
>  Regdata              = new((/dim_s(0),dim_s(1),nlagr/),"float")
> 
> n=-1
> do n=0,nlagr-1
>       n= n+1
>        Regdata(:,:,n) =regline(x(0:Nend-n-yLag), P1(:,:,yLag+n:Nend))
> end do ;
> 
> 
> This give me an error :
> fatal:Subscript out of range, error in subscript #2
> fatal:An error occurred reading P1
> 
> I try to replace regline by regCoef and get the same error message.
> 
> Thanks in advance!!
> 
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20171002/c93d571a/attachment.html>


More information about the ncl-talk mailing list