51468b135640c7b18dfbae479339d02b776fe002
[scilab.git] / scilab / modules / elementary_functions / help / en_US / searchandsort / find.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!--
3  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4  * Copyright (C) INRIA
5  *
6  * Copyright (C) 2012 - 2016 - Scilab Enterprises
7  *
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.
14  *
15  -->
16 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="en" xml:id="find">
17     <refnamediv>
18         <refname>find</refname>
19         <refpurpose>find indices of boolean vector or matrix true elements</refpurpose>
20     </refnamediv>
21     <refsynopsisdiv>
22         <title>Syntax</title>
23         <synopsis>[ii]=find(x [,nmax])
24             [i1,i2,..]=find(x [,nmax])
25         </synopsis>
26     </refsynopsisdiv>
27     <refsection>
28         <title>Arguments</title>
29         <variablelist>
30             <varlistentry>
31                 <term>x</term>
32                 <listitem>
33                     <para>may be a boolean vector,  a boolean matrix, a boolean
34                         hypermatrix, a "standard" matrix or hypermatrix
35                     </para>
36                 </listitem>
37             </varlistentry>
38             <varlistentry>
39                 <term>nmax</term>
40                 <listitem>
41                     <para>an integer giving the maximum number of indices to return. The default value is -1 which stands for "all". This option can be used for efficiency, to avoid searching all indices.</para>
42                 </listitem>
43             </varlistentry>
44             <varlistentry>
45                 <term>ii, i1, i2, ..  </term>
46                 <listitem>
47                     <para>integer vectors of indices or empty matrices</para>
48                 </listitem>
49             </varlistentry>
50         </variablelist>
51     </refsection>
52     <refsection>
53         <title>Description</title>
54         <para>
55             If <literal>x</literal> is a boolean matrix,
56         </para>
57         <para>
58             <literal>ii=find(x)</literal> returns the vector
59             of indices <literal>i</literal> for which <literal>x(i)</literal> is "true". If no true element
60             found find returns an empty matrix.
61         </para>
62         <para>
63             <literal>[i1,i2,..]=find(x)</literal> returns vectors of indices <literal>i1</literal> (for rows) and <literal>i2</literal> (for columns),..
64             such that <literal>x(i1(n),i2(n),..)</literal> is "true". If no true element
65             found find returns  empty matrices in <literal>i1</literal>,
66             <literal>i2</literal>, ...
67         </para>
68         <para>
69             if <literal>x</literal> is a standard matrix or hypermatrix <literal>find(x)</literal> is interpreted as
70             <literal>find(x&lt;&gt;0)</literal>
71         </para>
72         <para>
73             <literal>find([])</literal> returns <literal>[]</literal>
74         </para>
75     </refsection>
76     <refsection>
77         <title>Examples</title>
78         <programlisting role="example"><![CDATA[
79 beers=["Desperados", "Leffe", "Kronenbourg", "Heineken"];
80 find(beers=="Leffe") // OK
81 find(beers=="1664") // KO
82 find(beers=="Foster") // KO
83 beers=[beers, "Foster"]
84 find(beers=="Foster") // OK
85
86 A=rand(1,20);
87 w=find(A<0.4)
88 A(w)
89 w=find(A>100)
90
91 B=rand(1,20);
92 w=find(B<0.4,2) //at most 2 returned values
93
94 H=rand(4,3,5); //an hypermatrix
95 [i,j,k]=find(H>0.9)
96
97 H(i(1),j(1),k(1))
98  ]]></programlisting>
99     </refsection>
100     <refsection role="see also">
101         <title>See also</title>
102         <simplelist type="inline">
103             <member>
104                 <link linkend="boolean">boolean</link>
105             </member>
106             <member>
107                 <link linkend="extraction">extraction</link>
108             </member>
109             <member>
110                 <link linkend="insertion">insertion</link>
111             </member>
112             <member>
113                 <link linkend="vectorfind">vectorfind</link>
114             </member>
115         </simplelist>
116     </refsection>
117 </refentry>