Thanks your very much Samuel,<br><br>This works such fine for the application I intend to use this code for.<br><br>I assume that you are the author of this code, but, for some copyright issues, I would like that you confirm this point to me. If indeed you are, would you authorize me to use (and/or modify) your code as part of an application distributed under a GNU license? To preserve appropriate copyrights, I could either add your name and affiliation in a comment section at the beginning of the .sci file or you could maybe create such an .sci and sent it to me at your convenience.<br>

<br>Please, let me know what you would rather do.<br><br>Sebastien<br><br><div class="gmail_quote">On Tue, Nov 10, 2009 at 5:27 PM, Samuel Gougeon <span dir="ltr"><<a href="mailto:Samuel.Gougeon@univ-lemans.fr">Samuel.Gougeon@univ-lemans.fr</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">


  

<div bgcolor="#ffffff" text="#000000">
Hi,<br>
<br>
----- Message d'origine ----- <br>
De : Sébastien Bihorel <br>
Date : 08/11/2009 12:29:
<div><div></div><div class="h5"><blockquote type="cite">Dear Scilab users,<br>
  <br>
Is there an easy method to emulate the Matlab
ismember function to match numerical vectors to one another? I've 
tried several things with intersect but it does not seem to give
consistent results.<br>
  <br>
Here is a section of the Matlab help about ismember:<br>
[tf, loc] = ismember(A, S, ...) returns an array loc containing the <b>highest
  </b>index in S for each element in A that is a member of S.<br>
  <br>
  <br>
Here is an example of Scilab code that I tried<br>
a = [5 3 1 7 2 9 2 6 4 1 3 6 8 0 1 4];<br>
b=1:5;<br>
[v,ka,kb]=intersect(a,b,'c');<br>
  <br>
Surprisingly, ka is a mix of low, middle or high indexes... There must
a logic behind that, but I do not see the pattern.<br>
  <br>
  <br>
I am looking to extract only the highest indexes. Any help would be
appreciated. <br>
  <br>
Sebastien
</blockquote></div></div>
Here is a function that works like Matlab for giving loc :<br>
-----------<br>
function loc = ismember(A,S, highest)<br>
   // loc = ismember(A, S, highest)<br>
   //<br>
   // A : Matrix of booleans, integers, reals, complexes, polynomes<br>
   // S : Matrix of same datatype than S<br>
   // highest : Scalar boolean<br>
   //<br>
   // ismember() returns a matrix loc of A's format. loc(i,j) = linear <br>
   //  index in S of the first (highest ==%F) | last (highest==%T) <br>
   //  occurrence of A(i,j). Zero is returned in A(i,j) if no
occurrence is found<br>
   //<br>
   LA=length(A);<br>
   LS=length(S);<br>
   A2=matrix(A,LA,1)*ones(1,LS) ;<br>
   S2=(matrix(S,LS,1)*ones(1,LA)).' ;<br>
   d01  =double(A2==S2);<br>
   S_ind=ones(LA,1)*(1:LS);<br>
   tmp=d01.*S_ind;<br>
   if highest, <br>
       tmp2=max(tmp,'c'); <br>
   else <br>
       tmp(tmp==0)=%inf;    // removes zeros as min values<br>
       tmp2=min(tmp,'c');<br>
       tmp2(tmp2==%inf)=0;<br>
   end<br>
   loc=matrix(tmp2,size(A));<br>
endfunction<br>
--------<br>
ismember() works with any datatype, as long as elements <br>
can be multiplied by reals and compared each other with "==".<br>
<br>
A test with reals gives:<br>
-->A,S<br>
 A  =<br>
 <br>
    7.    3.  <br>
    2.    0.  <br>
    8.    1.  <br>
 S  =<br>
 <br>
    5.    8.    0.    4.  <br>
    3.    4.    7.    7.  <br>
    3.    6.    6.    2.  <br>
    7.    5.    5.    8.  <br>
 <br>
-->ismember(A,S,%f)<br>
 ans  =<br>
 <br>
    4.     2.  <br>
    15.    9.  <br>
    5.     0.  <br>
 <br>
-->ismember(A,S,%t)<br>
 ans  =<br>
 <br>
    14.    3.  <br>
    15.    9.  <br>
    16.    0.  <br>
<br>
HTH,<br>
<br>
Regards<br>
Samuel<br>
<br>
</div>

</blockquote></div><br>