[Scilab-users] vectorfind() upgrade to search partial matches and in hypermatrices

Samuel Gougeon sgougeon at free.fr
Wed Feb 8 14:28:01 CET 2017


Here it is:

https://codereview.scilab.org/#/c/19055/

Here is a sample with a matrix, and its results.
I ended up with hypermatrices. You can test it.

m = [
   1  0  0  0  1  0  1  0  1  0  0  1  1  1  1
   0  0  1  0  0  1  0  1  0  0  0  0  0  0  0
   0  1  1  1  0  0  1  1  1  0  1  1  0  0  1
   0  0  1  0  1  0  1  0  1  0  0  0  0  0  1
   ];
vectorfind(m, [0 0 0 0])
vectorfind(m, [1 0 0 0])
vectorfind(m, [0 1 1 1 0 0 1 1 1 0 1 1 0 0 1])

// With short v
vectorfind(m, [1 0 1],"c")
vectorfind(m, [1 1 0 0],"r")

// With %nan (never match)
m(2,2) = %nan;
vectorfind(m, [0 %nan 1 0])

// With %inf
m(2,2) = %inf;
vectorfind(m, [0 %inf 1 0])

--> m = [
   >   1  0  0  0  1  0  1  0  1  0  0  1  1  1  1
   >   0  0  1  0  0  1  0  1  0  0  0  0  0  0  0
   >   0  1  1  1  0  0  1  1  1  0  1  1  0  0  1
   >   0  0  1  0  1  0  1  0  1  0  0  0  0  0  1
   >   ];
--> vectorfind(m, [0 0 0 0])
  ans  =
    10.

--> vectorfind(m, [1 0 0 0])
  ans  =
    1.   13.   14.

--> vectorfind(m, [0 1 1 1 0 0 1 1 1 0 1 1 0 0 1])
  ans  =
    3.

--> // With short v
--> vectorfind(m, [1 0 1],"c")
  ans  =
    25.   33.   45.   57.

--> vectorfind(m,[1 1 0 0],"r")
  ans  =
    11.   43.

--> // With %nan (never match)
--> m(2,2) = %nan;
--> vectorfind(m, [0 %nan 1 0])
  ans  =
     []


--> // With %inf
--> m(2,2) = %inf;
--> vectorfind(m, [0 %inf 1 0])
  ans  =
    2.

This is a SEP :)
Any comments are welcome.

Cheers
Samuel



Le 08/02/2017 à 11:20, Dang Ngoc Chan, Christophe a écrit :
> Hello,
>
> I probably missed something obvious but here is my trouble :
> I have a vector a = 1:6
> and want to locate b = [2 3 4] inside a (the result being 2).
>
> So I know members() which locate any of the elements of b inside a
> and vectorfind() which can search a vector inside a matrix.
>
> I searched the archive of the list and found topics about Matlab ismember()
> and locating a phrase in a text.
>
> But none of these are convenient.
>
> As my vector is rather small, I can do
>
> aa = [a(1:$-2)  ;  a(2:$-1) ; a-3:$)]
>
> vectorfind(aa, b, "c")
>
> but I wonder if there is a better (vectorised) solution?
>
> Regards
>
> --
> Christophe Dang Ngoc Chan
> Mechanical calculation engineer
>
> Sidel Group
> Sidel Blowing & Services
> Avenue de la Patrouille de France
> CS 60627, Octeville-sur-Mer
> 76059 Le Havre cedex, France
>
>
> Tel: 33(0)2 32 85 89 32
> Fax: 33(0)2 32 85 91 17
>
> <http://www.sidel.com/>
> <mailto:christophe.dang at sidel.com>
>
> This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error), please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
>




More information about the users mailing list