<div dir="ltr">Hi Kevin thank you for your suggestion.<br>I don't want value of n to increase by 2 every loop iteration but normally from 0 to 20 in order to get 21 as "nlagr".<br><br>I removed the "n=-1" and "n=n+1" but still getting same error as before.<br><div><font face="Menlo">do n=0,nlagr-1</font><font face="Menlo"><span class="gmail-im"></span></font><br><font face="Menlo"><span class="gmail-im"></span></font></div><font face="Menlo"><span class="gmail-im">      Regdata(:,:,n) =regline(x(0:Nend-n-yLag), P1(:,:,yLag+n:Nend))<br>end do ;</span></font></div><div class="gmail_extra"><br><div class="gmail_quote">2017-10-03 1:44 GMT+02:00 Kevin Hallock <span dir="ltr"><<a href="mailto:hallock@ucar.edu" target="_blank">hallock@ucar.edu</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hi,<div><br></div><div>I noticed in your code’s do-loop that you’re incrementing n independently of the loop.</div><div><br></div><div>If you modify the loop to include “print(n)”:</div><div><font face="Menlo">do n=0,nlagr-1<br>      n = n+1</font></div><div><font face="Menlo">      print(n)<span class=""><br>      Regdata(:,:,n) =regline(x(0:Nend-n-yLag), P1(:,:,yLag+n:Nend))<br>end do ;<br></span></font></div><div><br></div><div>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/<wbr>), because n is being incremented by both the loop structure itself and the “n = n+1” line.</div><div><br></div><div>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><span style="font-family:Menlo">do n=0,nlagr-1,2</span><br style="font-family:Menlo"></div><div><font face="Menlo">      print(n)</font></div><div><font face="Menlo">end do</font></div><div><br></div><div>Otherwise, you might want to try removing the “n = n+1” line and rerunning your script.</div><div><br></div><div>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><br></div><div>I hope this helps,</div><div>Kevin</div><div><br></div><div><div><blockquote type="cite"><div><div class="h5"><div>On Oct 2, 2017, at 8:25 AM, Sancta Vega <<a href="mailto:sanctavega@gmail.com" target="_blank">sanctavega@gmail.com</a>> wrote:</div><br class="m_8840054564210121895Apple-interchange-newline"></div></div><div><div><div class="h5"><div dir="ltr"><div><div><div><div>according to this answer  <a href="https://www.ncl.ucar.edu/Support/talk_archives/2013/2968.html" target="_blank">https://www.ncl.ucar.edu/Suppo<wbr>rt/talk_archives/2013/2968.htm<wbr>l</a><br><br></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><br></div><div>This is my code :<br><br></div>dim_s   = dimsizes(P1)  ;;; <br> Nend = 5000 ; length of  x<br> nlagr= 21 ; +- 10 lag <br>  yLag = 10<br><br> Regdata              = new((/dim_s(0),dim_s(1),nlagr/<wbr>),"float")<br><br>n=-1<br>do n=0,nlagr-1<br>      n= n+1<br>       Regdata(:,:,n) =regline(x(0:Nend-n-yLag), P1(:,:,yLag+n:Nend))<br>end do ;<br><br><br></div>This give me an error :<br>fatal:Subscript out of range, error in subscript #2<br>fatal:An error occurred reading P1<br><br></div><div>I try to replace regline by regCoef and get the same error message.<br></div><div><br></div>Thanks in advance!!<br><div><div><br></div></div></div></div></div>
______________________________<wbr>_________________<br>ncl-talk mailing list<br><a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>List instructions, subscriber options, unsubscribe:<br><a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/<wbr>mailman/listinfo/ncl-talk</a><br></div></blockquote></div><br></div></div></blockquote></div><br></div>