1 <?xml version="1.0" encoding="UTF-8"?>
3 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
5 * Copyright (C) 2012 - 2016 - Scilab Enterprises
6 * Copyright (C) 2020 - Samuel GOUGEON
8 * This file is hereby licensed under the terms of the GNU GPL v2.0,
9 * pursuant to article 5.3.4 of the CeCILL v.2.1.
10 * This file was originally licensed under the terms of the CeCILL v2.1,
11 * and continues to be available under such terms.
12 * For more information, see the COPYING file which you should have received
13 * along with this program.
16 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
17 xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML"
18 xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org"
19 xml:lang="en" xml:id="find">
21 <refname>find</refname>
22 <refpurpose>gives the indices of %T or non-zero elements</refpurpose>
33 <title>Arguments</title>
39 Vector, matrix, or hypermatrix of booleans or of numbers.
40 All non-zero numbers are considered as %T.
41 Sparse matrices are accepted.
49 an integer giving the maximum number of indices to return.
50 The default value is -1 which stands for "all".
51 This option can be used for efficiency, to avoid searching all indices.
59 row vector of linearized indices of %T or non-zero elements, or empty matrix []
64 <term>i1, i2, ..</term>
67 row vectors of directional indices, or empty matrix []
74 <title>Description</title>
76 If <literal>x</literal> is a boolean matrix,
79 <literal>ii=find(x)</literal> returns the vector
80 of indices <literal>i</literal> for which <literal>x(i)</literal> is "true". If no true element
81 found find returns an empty matrix.
84 <literal>[i1,i2,..]=find(x)</literal> returns vectors of indices <literal>i1</literal> (for rows) and <literal>i2</literal> (for columns),..
85 such that <literal>x(i1(n),i2(n),..)</literal> is "true". If no true element
86 found find returns empty matrices in <literal>i1</literal>,
87 <literal>i2</literal>, ...
90 if <literal>x</literal> is a standard matrix or hypermatrix <literal>find(x)</literal> is interpreted as
91 <literal>find(x<>0)</literal>
94 <literal>find([])</literal> returns <literal>[]</literal>
98 <title>Examples</title>
102 <programlisting role="example"><![CDATA[
103 A = [%F %T %T %F ; %T %F %F %T]
108 --> A = [%F %T %T %F ; %T %F %F %T]
124 <programlisting role="example"><![CDATA[
125 B = [0 -1 0 3 ; 0 -1 -0.4 0]
131 --> B = [0 -1 0 3 ; 0 -1 -0.4 0]
140 --> [i, j] = find(B);
149 With an input hypermatrix of numbers:
151 <programlisting role="example"><![CDATA[
152 E = grand(2,5,2,"uin",1,6)
156 --> E = grand(2,5,2,"uin",1,6)
170 With an input numerical or boolean sparse matrix:
172 <programlisting role="example"><![CDATA[
181 // With input boolean sparse
190 3. 4. 5. 7. 9. 13. 14. 15. 18.
196 --> // With input boolean sparse
199 ( 3, 6) sparse boolean matrix
217 With the result of a boolean element-wise condition on texts:
219 <programlisting role="example"><![CDATA[
220 beers = ["Desperados", "Leffe", "Kronenbourg", "Heineken"];
221 find(beers == "Leffe")
222 find(beers == "1664")
225 --> find(beers == "Leffe")
229 --> find(beers == "1664")
234 Addressing selected elements:
236 <programlisting role="example"><![CDATA[
237 // a) Through their linearized indices:
238 H = [ 0 -2 -8 4 -5 -1
244 // b) Directly through the array of their boolean status:
249 --> // a) Through their linearized indices:
250 --> H = [ 0 -2 -8 4 -5 -1
254 --> L(find(L < 0)) = -10
256 0. -10. -10. 4. -10. -10.
257 -10. 2. -10. 5. 0. 1.
259 --> // b) Directly through the array of their boolean status:
263 0. -10. -10. 4. -10. -10.
264 -10. 2. -10. 5. 0. 1.
267 <refsection role="see also">
268 <title>See also</title>
269 <simplelist type="inline">
271 <link linkend="vectorfind">vectorfind</link>
274 <link linkend="grep">grep</link>
277 <link linkend="findobj">findobj</link>
280 <link linkend="boolean">boolean</link>