<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Hello Phil,<br>
      <br>
      This should work:<br>
      <br>
      <font size="-1"><tt>--> [A,B] = ndgrid(rand(1,1000),
          rand(1,10000));  // test's data</tt><tt><br>
        </tt><tt>--> size(A)</tt><tt><br>
        </tt><tt> ans  =</tt><tt><br>
        </tt><tt>   1000.   10000.</tt><tt><br>
        </tt><tt>--> [v, i] = min(abs(A-B));</tt></font><br>
      <br>
      The minimal distances are in v, the index of the closest in B are
      in i.<br>
      <br>
      Regards<br>
      Samuel<br>
      <br>
      Le 15/02/2019 à 21:46, P M a écrit :<br>
    </div>
    <blockquote
cite="mid:CACf7ODv6SyWvu=2Qjdo0WGBMHJRQyyn4XnDe3btYu-uUMec-0A@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>Hi experts,</div>
        <div><br>
        </div>
        <div>my problem is (I guess) a very common thing, but I somehow
          get stucked.</div>
        <div><br>
        </div>
        <div>I aim to find the nearest position of ANY value in array_1
          to ANY position in array_2.</div>
        <div><br>
        </div>
        <div>e.g.:</div>
        <div><br>
        </div>
        <div>A = array of doubles with 1000 elements.</div>
        <div>B = array of doubles with 10'000 elements.</div>
        <div><br>
        </div>
        <div>for each element of A I want to know it's nearest value in
          B.</div>
        <div>Also I want to know the index of the nearest value in B.<br>
        </div>
        <div><br>
        </div>
        <div>I could do it in a bunch of for-loops, but this is way to
          slow, since this loops 1000 values against 10'000 values of B.<br>
        </div>
        <div><br>
        </div>
        <div>something like this:</div>
        <div><br>
        </div>
        <div>nearesVal   = zeros(1000);<br>
        </div>
        <div>distIndex    = zeros(1000);<br>
        </div>
        <div><br>
        </div>
        <div>for i=1:1000</div>
        <div>  d = 1000000; // just a rediculous big number that is much
          greater than max(A) & max(B)
        </div>
        <div>  for j = 1:10000</div>
        <div>     act_dist = abs( A(i) - B(j) );     // actual minimal
          distance   <br>
        </div>
        <div>     if act_dist <= d</div>
        <div>        d = act_dist;</div>
        <div>        nearestVal(i) = B(j);
        </div>
        <div>        distIndex(i)  = j;</div>
        <div>      end</div>
        <div>   end</div>
        <div>end<br>
        </div>
        <div><br>
        </div>
        <div>I do not have Scilab at hand, while I am writing this, but
          it looks like it should work :-)</div>
        <div><br>
        </div>
        <div>Thanks</div>
        <div>Phil<br>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:users@lists.scilab.org">users@lists.scilab.org</a>
<a class="moz-txt-link-freetext" href="http://lists.scilab.org/mailman/listinfo/users">http://lists.scilab.org/mailman/listinfo/users</a>
</pre>
    </blockquote>
    <p><br>
    </p>
  </body>
</html>