<div dir="ltr"><div>Chang, use the same general approach.  In this case, compare x(n-1) to x(n), and remember the positions where the value changed.  The essential logic is in the single line "change =".</div><div><br></div><div>    x = (/1,1,1,5,5,5,5,31,31/)<br>   <span class="gmail-Apple-converted-space"> </span>nx = dimsizes (x)<br>   <span class="gmail-Apple-converted-space"> </span>previous = new (nx, typeof (x))<br>   <span class="gmail-Apple-converted-space"> </span>previous(0) = x(0) - 1      ; need this to get correct answer for first position<br>   <span class="gmail-Apple-converted-space"> </span>previous(1:nx-1) = x(0:nx-2)       ; vector shifted one position to the right<br>   <span class="gmail-Apple-converted-space"> </span>change = (x(:) .ne. previous(:))   ; all places that changed value<br>   <span class="gmail-Apple-converted-space"> </span>istarts = ind (change)<br><br></div><div>   <span class="gmail-Apple-converted-space"> </span>print (istarts+"")<br>    (0)     0<br>    (1)     3<br>    (2)     7<br></div><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Mar 6, 2023 at 2:06 AM Xi Chang <<a href="mailto:xi.chang01@gmail.com">xi.chang01@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="auto">Thanks a lot Dave. Would you please suggest me hot get the first index of each sequence without any missing values in between. For example, i would like to get the first index of each sequence marked by flags:</div><div dir="auto"><br></div><div dir="auto">x= (/1,1,1,5,5,5,5,31,31/)</div><div dir="auto"><br></div><div dir="auto">Results will be: 0, 3, and 7</div><div dir="auto"><br></div><div dir="auto">Thank you!</div><div dir="auto">Chang,</div><div dir="auto"><br></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Feb 6, 2023 at 17:01 Dave Allured - NOAA Affiliate <<a href="mailto:dave.allured@noaa.gov" target="_blank">dave.allured@noaa.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>When analyzing sequences, it is often useful to compare adjacent elements by using a vector shifted by one position.  Then find an expression that is true in the positions of interest, and false everywhere else.<br><br>    status = .not. ismissing (x)<br>    nx = dimsizes (x)<br>    previous = new (nx, logical)<br>    previous(0) = False      ; need this to get correct answer for first position<br>    previous(1:nx-1) = status(0:nx-2)       ; vector shifted one position to the right<br>    change = status(:) .and. .not. previous(:)     ; all places that changed from missing to not<br>    istarts = ind (change)<br><br></div><div>     print (istarts+"")                         <br></div></div><div dir="ltr"><div>    (0)     4<br>    (1)     12<br>    (2)     16</div><div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Feb 6, 2023 at 7:18 PM Xi Chang via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi NCL community,<div><br></div><div>Is there anyone who can help me on how to return the first index of each sequence in 1D data?</div><div>For example,</div><div><br></div><div>x = (/-999,-999,-999,-999,1,1,1,1,1,-999,-999,-999,1,1,1,-999,1,1,1/)</div><div>x@_FillValue=-999<br></div><div><br></div><div>There are 3 sequences of data in that 1D time series, how could I get the first index of each sequence, so that the answer would be:</div><div><br></div><div>(0)    4 </div><div>(1) 12 </div><div>(2)    16 </div><div><br></div><div>Thanks </div><div>Chang</div></div>
</blockquote></div></div>
</blockquote></div></div>
</blockquote></div></div>