<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi,<div class=""><br class=""></div><div class="">I noticed in your code’s do-loop that you’re incrementing n independently of the loop.</div><div class=""><br class=""></div><div class="">If you modify the loop to include “print(n)”:</div><div class=""><font face="Menlo" class="">do n=0,nlagr-1<br class=""> n = n+1</font></div><div class=""><font face="Menlo" class=""> print(n)<br class=""> Regdata(:,:,n) =regline(x(0:Nend-n-yLag), P1(:,:,yLag+n:Nend))<br class="">end do ;<br class=""></font></div><div class=""><br class=""></div><div class="">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.</div><div class=""><br class=""></div><div class="">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:</div><div class=""><span style="font-family: Menlo;" class="">do n=0,nlagr-1,2</span><br style="font-family: Menlo;" class=""></div><div class=""><font face="Menlo" class=""> print(n)</font></div><div class=""><font face="Menlo" class="">end do</font></div><div class=""><br class=""></div><div class="">Otherwise, you might want to try removing the “n = n+1” line and rerunning your script.</div><div class=""><br class=""></div><div class="">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.</div><div class=""><br class=""></div><div class="">I hope this helps,</div><div class="">Kevin</div><div class=""><br class=""></div><div class=""><div><blockquote type="cite" class=""><div class="">On Oct 2, 2017, at 8:25 AM, Sancta Vega <<a href="mailto:sanctavega@gmail.com" class="">sanctavega@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class=""><div class="">according to this answer <a href="https://www.ncl.ucar.edu/Support/talk_archives/2013/2968.html" target="_blank" class="">https://www.ncl.ucar.edu/Suppo<wbr class="">rt/talk_archives/2013/2968.<wbr class="">html</a><br class=""><br class=""></div>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 .<br class=""><br class=""></div><div class="">This is my code :<br class=""><br class=""></div>dim_s = dimsizes(P1) ;;; <br class=""> Nend = 5000 ; length of x<br class=""> nlagr= 21 ; +- 10 lag <br class=""> yLag = 10<br class=""><br class=""> Regdata = new((/dim_s(0),dim_s(1),nlagr/),"float")<br class=""><br class="">n=-1<br class="">do n=0,nlagr-1<br class=""> n= n+1<br class=""> Regdata(:,:,n) =regline(x(0:Nend-n-yLag), P1(:,:,yLag+n:Nend))<br class="">end do ;<br class=""><br class=""><br class=""></div>This give me an error :<br class="">fatal:Subscript out of range, error in subscript #2<br class="">fatal:An error occurred reading P1<br class=""><br class=""></div><div class="">I try to replace regline by regCoef and get the same error message.<br class=""></div><div class=""><br class=""></div>Thanks in advance!!<br class=""><div class=""><div class=""><br class=""></div></div></div>
_______________________________________________<br class="">ncl-talk mailing list<br class=""><a href="mailto:ncl-talk@ucar.edu" class="">ncl-talk@ucar.edu</a><br class="">List instructions, subscriber options, unsubscribe:<br class="">http://mailman.ucar.edu/mailman/listinfo/ncl-talk<br class=""></div></blockquote></div><br class=""></div></body></html>