[Scilab-users] find & vectorization

Samuel Gougeon sgougeon at free.fr
Wed Dec 28 12:55:21 CET 2016


Hello,

Le 28/12/2016 09:16, 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));

When with "==" you compare a matrix A to a scalar, the result is a 
matrix with the sizes of A, and find() works well (it just returns the 
indices of true components).
When with "==" you compare a matrix A to another one B having the same 
sizes, then "==" works element-wise: the result is a matrix with the 
sizes of A, and find() still works well.
When with "==" you compare a matrix A to another one B NOT having the 
same sizes, then "==" returns simply %F, and find(%F) returns []
https://help.scilab.org/docs/6.0.0/en_US/comparison.html

What you try to do is achieved with members().

Samuel

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


More information about the users mailing list