[Scilab-users] find & vectorization

Rafael Guerra jrafaelbguerra at hotmail.com
Wed Dec 28 21:51:51 CET 2016


Hi,

Check out this solution:

[vs,k] = gsort(v,'g','i');
[aux,ka,kb] = intersect(vs,A(:,1));
index = kb(k)

index  =
    2.    3.    6.

Regards,
Rafael

From: users [mailto:users-bounces at lists.scilab.org] On Behalf Of paul.carrico at free.fr
Sent: Wednesday, December 28, 2016 2:59 PM
To: Users mailing list for Scilab <users at lists.scilab.org>
Subject: Re: [Scilab-users] find & vectorization

Thanks for your help.

Well I wanted to get the position of each scalar, as the loop does; I'll be content to use a loop

Thanks for your time.

Paul

Le 2016-12-28 14:43, Samuel Gougeon a écrit :
Le 28/12/2016 09:16, paul.carrico at free.fr<mailto:paul.carrico at free.fr> a écrit :


Hi all

I do not understand why the following code does not work when I try
to
use vectorization (many trials)?

What am I doing wrong ?

Thanks

Paul
################################################################

mode(0)

A = [ 1 2 9 0 10 6 ; 5 3 8 8 0 9 ; 5 9 1 0 3 9]'
v = [2 9 6]'

index = zeros(3,1);
for i = 1 : 3
index(i) = find(A(:,1) == v(i));
end
disp(index)

i = [1 : 3]';
index2 = zeros(3,1); //pause
index2(i,1) = find(A(:,1) == v(i,1));

Actually, what you want and try to do is unclear. Even members() could
be not appropriate.
You can easily get an error even with your unvectorized version, as
soon as one of the v components will appears several times in A(:,1)

SG
_______________________________________________
users mailing list
users at lists.scilab.org<mailto:users at lists.scilab.org>
http://lists.scilab.org/mailman/listinfo/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20161228/53880aa5/attachment.htm>


More information about the users mailing list