<div dir="ltr"><div><div><div><div><div><div><div><div>I do not think you can do it without a loop.<br><br>function get_dup_elements(a[*], b[*])<br>begin<br> dima = dimsizes(a)<br> dimb = dimsizes(b)<br> ndup = -1<br><br> if (dima.le.dimb) then<br> dimd = new( dima, typeof(a))<br> do n=0,dima-1<br> ii := ind(b.eq.a(n))<br> if (.not.ismissing(ii(0))) then<br> ndup = ndup+1<br> dimd(ndup) = a(n)<br> end if<br> end do<br> else<br> dimd = new( dimb, typeof(a))<br> do n=0,dimb-1<br> ii := ind(a.eq.b(n))<br> if (.not.ismissing(ii(0))) then<br> ndup = ndup+1<br> dimd(ndup) = b(n)<br> end if<br> end do<br><br> end if<br><br> return(dimd(0:ndup))<br>end<br><br>A = (/ 1, 2, 3, 4, 5, 6, 7, 8, 9/)<br>B = (/ 2, 14, 7, 1/)<br><br>dup = get_dup_elements(A,B)<br>print(dup)<br><br></div><div>;; sort(dup) ; ascending order<br></div><div><br><br></div></div></div></div></div></div></div></div><div><div> </div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 17, 2014 at 1:59 AM, Lin Wang <span dir="ltr"><<a href="mailto:wanglin@post.iap.ac.cn" target="_blank">wanglin@post.iap.ac.cn</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear all,<br><br>Suppose: <br>A = (/ 1, 2, 3, 4, 5, 6, 7, 8, 9/)<br>B = (/ 2, 14, 7, 1/)<br><br>If don't use loop, how to find the same elements between A and B such as (/1, 2, 7/)? Thanks.<br><br>Best wishes,<br>Lin Wang<br><br><br><br>_______________________________________________<br>
ncl-talk mailing list<br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>