[scilab-Users] Matlab ismember

Michaël Baudin michael.baudin at scilab.org
Mon Jan 17 16:26:32 CET 2011


See the discussion at :

http://bugzilla.scilab.org/process_bug.cgi

Best regards,

Michaël Baudin

Le 17/01/2011 16:10, Michaël Baudin a écrit :
> Hi,
>
> Ok, now I remember, it is there :
>
> http://forge.scilab.org/index.php/p/number/source/tree/HEAD/macros/number_ismember.sci
>
> Unfortunately, I have not released this function in the binary release 
> yet.
> Here is a simplified version:
>
> function tf = number_ismember ( a , s )
>     // Array elements that are members of set.
>     //
>     // Calling Sequence
>     // tf = number_ismember ( a , s )
>     //
>     // Parameters
>     // a : a ma-by-na matrix
>     // s : a 1-by-ns matrix
>     // tf : a ma-by-na matrix of booleans, tf(i,j) is %t if there is 
> an entry in s matching a(i,j).
>     //
>     // Description
>     // Search in a the entries which are in s.
>     //
>     // Uses vectorized statements, based on the Kronecker product.
>     // The intermediate memory required is ma*na*ns.
>     //
>     // Examples
>     // a = (1:5)'
>     // s = [0 2 4 6 8 10 12 14 16 18 20]
>     // tf = number_ismember ( a , s )
>     // expected = [%f %t %f %t %f]'
>     //
>     // // An example with a matrix
>     // a = [
>     // 7 35 14 86 76
>     // 15 51 24 96 49
>     // 35 40 46 35 93
>     // 85 34 74 82 22
>     // ];
>     // s = [51 74 22 15 86]
>     // tf = number_ismember(a, s)
>     //
>     // Authors
>     // Copyright (C) 2010 - DIGITEO - Michael Baudin
>
>     //
>     // Check size
>     // a can have any shape
>     if ( s==[] ) then
>       tf=(ones(a)==zeros(a))
>       return
>     end
>     //
>     // Check content
>     // Nothing to do.
>     //
>     // Proceed...
>     if ( a==[] ) then
>       tf=[]
>       return
>     end
>     //
>     // Convert a into a column vector
>     ma = size(a,"r")
>     na = size(a,"c")
>     a=a(:)
>     //
>     ns = size(s,"c")
>     sp = s .*. ones(na*ma,1)
>     ap = a .*. ones(1,ns)
>     tf = or(ap==sp,"c")
>     //
>     // Convert tf into the same shape as a
>     tf=matrix(tf,ma,na)
> endfunction
>
> This is an example:
>
> -->     a = [
> -->     7 35 14 86 76
> -->     15 51 24 96 49
> -->     35 40 46 35 93
> -->     85 34 74 82 22
> -->     ];
>
> -->     s = [51 74 22 15 86]
>  s  =
>
>     51.    74.    22.    15.    86.
>
> -->     tf = number_ismember(a, s)
>  tf  =
>
>   F F F T F
>   T T F F F
>   F F F F F
>   F F T F T
>
> Best regards,
>
> Michaël
>
> Le 16/01/2011 19:56, dragomir nedeltchev a écrit :
>> thank you very much
>>
>> --- On *Sun, 1/16/11, Samuel Gougeon 
>> /<Samuel.Gougeon at univ-lemans.fr>/* wrote:
>>
>>
>>     From: Samuel Gougeon <Samuel.Gougeon at univ-lemans.fr>
>>     Subject: Re: [scilab-Users] Matlab ismember
>>     To: users at lists.scilab.org
>>     Date: Sunday, January 16, 2011, 6:21 PM
>>
>>
>>     Hello,
>>
>>     dragomir nedeltchev <dnedelchev65 at yahoo.com
>>     </mc/compose?to=dnedelchev65 at yahoo.com>> a écrit :
>>
>>     > Hi, Can you help me replicate MATLAB's ismember in SciLab?
>>     Thanks. Drago
>>
>>     You may read the followinf thread:
>>     http://lists.scilab.org/cgi-bin/ezmlm-browse?list=users&cmd=threadindex&month=200911&threadid=epdldcdicfagcdofccbc
>>     <http://lists.scilab.org/cgi-bin/ezmlm-browse?list=users&cmd=threadindex&month=200911&threadid=epdldcdicfagcdofccbc>
>>
>>     When you have well defined keywords as here, you should use them
>>     to search
>>     through the archives:
>>     http://lists.scilab.org/cgi-bin/ezmlm-browse?list=users&cmd=search <http://lists.scilab.org/cgi-bin/ezmlm-browse?list=users&cmd=search>
>>
>>     Regards
>>     Samuel
>>
>>
>>
>
>
> -- 
> Michaël Baudin
> Ingénieur de développement
> michael.baudin at scilab.org
> -------------------------
> Consortium Scilab - Digiteo
> Domaine de Voluceau - Rocquencourt
> B.P. 105 - 78153 Le Chesnay Cedex
> Tel. : 01 39 63 56 87 - Fax : 01 39 63 55 94
>


-- 
Michaël Baudin
Ingénieur de développement
michael.baudin at scilab.org
-------------------------
Consortium Scilab - Digiteo
Domaine de Voluceau - Rocquencourt
B.P. 105 - 78153 Le Chesnay Cedex
Tel. : 01 39 63 56 87 - Fax : 01 39 63 55 94


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20110117/b8f611f8/attachment.htm>


More information about the users mailing list