Hi, I think that you can just do:<br><br><div><p style="margin: 0px; font-size: 12px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);">ncl 0> A = (/ 1, 2, 3, 4, 5, 6, 7, 8, 9/)</p>
<p style="margin: 0px; font-size: 12px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);">ncl 1> B = (/ 2, 14, 7, 1/)</p>
<p style="margin: 0px; font-size: 12px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);">ncl 2> </p>
<p style="margin: 0px; font-size: 12px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);">ncl 3> C = A(ind(.not.ismissing(get1Dindex(B,A))))</p>
<p style="margin: 0px; font-size: 12px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);">ncl 4> print(C)</p>
<p style="margin: 0px; font-size: 12px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0); min-height: 16px;"><br></p>
<p style="margin: 0px; font-size: 12px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0); min-height: 16px;"><br></p>
<p style="margin: 0px; font-size: 12px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);">Variable: C</p>
<p style="margin: 0px; font-size: 12px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);">Type: integer</p>
<p style="margin: 0px; font-size: 12px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);">Total Size: 12 bytes</p>
<p style="margin: 0px; font-size: 12px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);"> 3 values</p>
<p style="margin: 0px; font-size: 12px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);">Number of Dimensions: 1</p>
<p style="margin: 0px; font-size: 12px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);">Dimensions and sizes: [3]</p>
<p style="margin: 0px; font-size: 12px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);">Coordinates: </p>
<p style="margin: 0px; font-size: 12px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);">(0) 1</p>
<p style="margin: 0px; font-size: 12px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);">(1) 2</p>
<p style="margin: 0px; font-size: 12px; font-family: Monaco; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);">(2) 7</p><br>Good luck!</div><div><br></div><div>Yongjie Huang<br><br>> Date: Fri, 19 Dec 2014 08:39:55 -0700<br>> From: Dennis Shea <shea@ucar.edu><br>> Subject: Re: [ncl-talk] How to find the same elements in two matrixes<br>> To: Lin Wang <wanglin@post.iap.ac.cn><br>> Cc: ncl-talk <ncl-talk@ucar.edu><br>> Message-ID:<br>>         <CAOF1d_5DLMe=Tv794H9ekb598XgNKcuf9AtES=9X8ABhj9pFWg@mail.gmail.com><br>> Content-Type: text/plain; charset="utf-8"<br>> <br>> I do not think you can do it without a loop.<br>> <br>> function get_dup_elements(a[*],&nb
sp;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>> &n
bsp; 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>> ;; sort(dup) ; ascending order<br>> <br>> <br>> <br>> <br>> On Wed, Dec 17, 2014 at 1:59 AM, Lin Wang <wanglin@post.iap.ac.cn> wrote:<br>> <br>> > Dear all,<br>> ><br>> > Suppose:<br>> > A = (/ 1, 2, 3, 4, 5, 6, 7, 8, 9/)<br>> > B = (/ 2, 14, 7, 1/)<br>> ><br>>&nbs
p;> If don't use loop, how to find the same elements between A and B such as<br>> > (/1, 2, 7/)? Thanks.<br>> ><br>> > Best wishes,<br>> > Lin Wang<br>> ><br><span><br><div><font face="Comic Sans MS">-----------------------------------------------------------------------------------</font></div><font face="Comic Sans MS">HUANG Yong-jie<br>Key Laboratory of Cloud-Precipitation Physics and Severe Storms (LACS), <br>Institute of Atmospheric Physics, Chinese Academy of Sciences<br>Email Address: huangyj@mail.iap.ac.cn OR huangynj@gmail.com </font><div><span style="font-family: 'Comic Sans MS';">-----------------------------------------------------------------------------------</span><font face="C
omic Sans MS"><br></font><br></div></span></div><br><br><br>