[Scilab-users] Search for a subvector in a vector

classic Classic list List threaded Threaded
5 messages Options
Christophe Dang Ngoc Chan Christophe Dang Ngoc Chan
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] Search for a subvector in a vector

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:[hidden email]>

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
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
--
Christophe Dang Ngoc Chan
Mechanical calculation engineer
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: Search for a subvector in a vector

Hello Christophe,

Having the same need, i have recently implemented a vectorized solution,
by the way truly extended to hypermatrices (up to now only the first
page of hypermatrix was considered and searched in).

I am posting it on the CodeReview. I still need a bit of time to update
the help page. It shall be available in 6.1, but you can download and
use it from the codeReview (will post the URL here just after commiting).

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:[hidden email]>
>
> 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
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/users
>

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Christophe Dang Ngoc Chan Christophe Dang Ngoc Chan
Reply | Threaded
Open this post in threaded view
|

Re: {EXT} Re: Search for a subvector in a vector

Hello,

> De : users [mailto:[hidden email]] De la part de Samuel Gougeon
> Envoyé : mercredi 8 février 2017 14:06
>
> I have recently implemented a vectorized solution
> [...]
> I am posting it on the CodeReview.
> [...]
> It shall be available in 6.1, but you can download and use it from the codeReview

OK, so I didn't miss anything (-:

Thanks for sharing your code, I'll have a look at it.

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:[hidden email]>
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
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
--
Christophe Dang Ngoc Chan
Mechanical calculation engineer
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

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

In reply to this post by Christophe Dang Ngoc Chan
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:[hidden email]>
>
> 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
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/users
>

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: vectorfind() upgrade to search partial matches and in hypermatrices

Le 08/02/2017 à 14:28, Samuel Gougeon a écrit :
> Here it is:
>
> https://codereview.scilab.org/#/c/19055/

Follow-up there:
http://mailinglists.scilab.org/Scilab-users-vectorfind-upgrade-SEP-tt4036885.html

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users