<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 think there might be an issue with the P1 variable passed as an argument to regline(). The <a href="https://www.ncl.ucar.edu/Document/Functions/Built-in/regline.shtml" class="">documentation for the regline() function</a> indicates that both arguments should be 1-dimensional arrays of the same length, although in your code P1 is being passed as a 3-dimensional array. You may want to try something like this:</div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">dims_P1 = dimsizes(P1)</font></div><div class=""><font face="Menlo" class="">do a=0,dims_P1(0)-1</font></div><div class=""><font face="Menlo" class=""> do b=0,dims_P1(1)-1</font></div><div class=""><font face="Menlo" class=""> do n=0,nlagr-1</font></div><div class=""><font face="Menlo" class=""> Regdata(a,b,n) = regline(x(0:Nend-n-yLag), P1(a,b,yLag+n:Nend))</font></div><div class=""><font face="Menlo" class=""> end do</font></div><div class=""><font face="Menlo" class=""> end do</font></div><div class=""><font face="Menlo" class="">end do</font></div><div class=""><br class=""></div><div class="">Kevin</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Oct 3, 2017, at 2:58 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="">Hi Kevin thank you for your suggestion.<br class="">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 class=""><br class="">I removed the "n=-1" and "n=n+1" but still getting same error as before.<br class=""><div class=""><font face="Menlo" class="">do n=0,nlagr-1</font><font face="Menlo" class=""><span class="gmail-im"></span></font><br class=""><font face="Menlo" class=""><span class="gmail-im"></span></font></div><font face="Menlo" class=""><span class="gmail-im"> Regdata(:,:,n) =regline(x(0:Nend-n-yLag), P1(:,:,yLag+n:Nend))<br class="">end do ;</span></font></div><div class="gmail_extra"><br class=""><div class="gmail_quote">2017-10-03 1:44 GMT+02:00 Kevin Hallock <span dir="ltr" class=""><<a href="mailto:hallock@ucar.edu" target="_blank" class="">hallock@ucar.edu</a>></span>:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" 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)<span class=""><br class=""> Regdata(:,:,n) =regline(x(0:Nend-n-yLag), P1(:,:,yLag+n:Nend))<br class="">end do ;<br class=""></span></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/<wbr class="">), 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 class=""><blockquote type="cite" class=""><div class=""><div class="h5"><div class="">On Oct 2, 2017, at 8:25 AM, Sancta Vega <<a href="mailto:sanctavega@gmail.com" target="_blank" class="">sanctavega@gmail.com</a>> wrote:</div><br class="m_8840054564210121895Apple-interchange-newline"></div></div><div class=""><div class=""><div class="h5"><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.htm<wbr class="">l</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/<wbr class="">),"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></div></div>
______________________________<wbr class="">_________________<br class="">ncl-talk mailing list<br class=""><a href="mailto:ncl-talk@ucar.edu" target="_blank" class="">ncl-talk@ucar.edu</a><br class="">List instructions, subscriber options, unsubscribe:<br class=""><a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank" class="">http://mailman.ucar.edu/<wbr class="">mailman/listinfo/ncl-talk</a><br class=""></div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></body></html>