[scilab-Users] Emulate Matlab's ismember function in Scilab

Samuel Gougeon Samuel.Gougeon at univ-lemans.fr
Wed Nov 11 18:03:11 CET 2009


Hello Sébastien,

Sébastien Bihorel <pomchip at free.fr> a écrit :

> Thanks your very much Samuel,
>
> This works such fine for the application I intend to use this code for.
>
> 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.

That's right

> 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.

I will do so as soon as possible. I am aiming to propose this function (with
improvements) as a SEP for Scilab ; then, i must get more infos from the
Scilab's consortium about licensing of such contribs. I guess that it will
be either under a GPL or Cecill license.

If this matter urges for you, please note my Affiliation:
Samuel Gougeon - Université du Maine, France (2009)

Here is an improved release of ismember(), that now supports
%inf values either in A or S, and with fixed mistakes in the
head_comments:
----
function loc=ismember(A,S, highest)
    // loc = ismember(A, S, highest)
    //
    // A : Matrix of booleans, integers, reals, complexes, polynomes
    //     (or any datatype supporting #*R real multiplication and ==
    //     inter-comparison).
    // S : Matrix of same datatype than S
    // highest : Scalar boolean
    //
    // ismember() returns a matrix loc of A's format. loc(i,j) = linear
    //  index in S of the first (highest ==%F), or the  last (highest==%T)
    //  occurrence of A(i,j). loc(i,j) returns zero if A(i,j) is not found.
    //
    // COPYRIGHT : Samuel GOUGEON  - Université du Maine, France (2009)
    // LICENSE : CeCILL
    //
   LA=length(A);
   LS=length(S);
   A2=matrix(A,LA,1)*ones(1,LS) ;
   S2=(matrix(S,LS,1)*ones(1,LA)).' ;
   d01  =double(A2==S2);
   S_ind=ones(LA,1)*(1:LS);
   tmp=d01.*S_ind;
   if highest,
     tmp2=max(tmp,'c');
   else
     tmp(tmp==0)=2*LS;   // Masks zeros=unfound as min values
     tmp2=min(tmp,'c');
     tmp2(tmp2==2*LS)=0;  // Retrieves zeros=unfound
   end
   loc=matrix(tmp2,size(A));
endfunction
----
-->A,S
  A  =

     7.    3.
    Inf    0.
     8.    1.
  S  =

     5.    8.    0.    4.
     3.    4.    7.    7.
     3.   Inf   Inf    2.
     7.    5.    5.    8.

-->ismember(A,S,%f)
  ans  =

     4.    2.
     7.    9.
     5.    0.

-->ismember(A,S,%t)
  ans  =

     14.    3.
     11.    9.
     16.    0.
---------
Regards
Samuel




More information about the users mailing list