1 <?xml version="1.0" encoding="UTF-8"?>
3 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 * Copyright (C) 2008 - INRIA
5 * Copyright (C) 2012 - 2016 - Scilab Enterprises
6 * Copyright (C) 2017 - 2019 - 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:ns4="http://www.w3.org/1999/xhtml"
18 xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook"
19 xmlns:scilab="http://www.scilab.org" xml:id="unique" xml:lang="pt">
21 <refname>unique</refname>
22 <refpurpose>remover todos os componentes duplicados de um vetor ou uma matriz
26 <title>Seqüência de Chamamento</title>
28 [N, km, kn, nb] = unique(M)
29 [N, km, kn, nb] = unique(M, orient)
30 [N, km, kn, nb] = unique(.., "keepOrder")
31 [N, km, kn, nb] = unique(.., "uniqueNan")
34 <refsection role="parameters">
35 <title>Parâmetros</title>
40 <para>vetor ou matriz de números ou strings </para>
46 <para>flag com valores possíveis : 1 ou "r", 2 ou "c".
47 It can't be used if <varname>M</varname> is an hypermatrix.
58 If <varname>orient</varname> is not used: Vector of extracted
59 <varname>M</varname> components sorted in ascending order.
60 If <varname>M</varname> is a row vector, <varname>N</varname> is also
61 a row vector. In all other <varname>M</varname> cases,
62 <varname>N</varname> is a matrix or a column vector.
66 If <varname>orient</varname> is used: Matrix of extracted
67 <varname>M</varname> rows or columns, sorted in lexicographic ascending order.
77 Vector of indices of first encountered occurences, such that
78 <literal>N(i) = M(k(i))</literal> or <literal>N(i,:) = M(k(i),:)</literal>
79 or <literal>N(:,i) = M(:,k(i))</literal>.
82 <varname>k</varname> is a row if <varname>M</varname> is a row or if
83 <literal>orient="c"</literal> is used. Otherwise it's a column.
91 Vector of indices of first encountered occurrences, such that
92 <literal>M(i) = N(kn(i))</literal> or <literal>M(i,:) = N(kn(i),:)</literal>
93 or <literal>M(:,i) = N(:,kn(i))</literal>.
101 Vector of integers > 0, with the same <varname>k</varname> shape:
102 Numbers of occurences in <varname>M</varname> of respective unduplicated
103 entities (components, rows, columns) returned in <varname>N</varname>.
109 <refsection role="description">
110 <title>Descrição</title>
112 <literal>unique(M)</literal> retorna um vetor que retém as entradas
113 únicas de <literal>M</literal> em ordem ascendente.
116 <literal>unique(M,"r")</literal> ou
117 <literal>unique(M,1)</literal>retorna as linhas únicas de
118 <literal>M</literal> em ordem lexicográfica ascendente.
121 <literal>unique(M,"c")</literal> ou
122 <literal>unique(M,2)</literal>retorna as linhas únicas de
123 <literal>M</literal> em ordem lexicográfica ascendente.
126 <literal>unique(M,.. "keepOrder")</literal> returns <varname>M</varname> unduplicated
127 entries in their original order in <varname>M</varname>.
128 <literal>"keepOrder"</literal> is case-insensitive.
131 <literal>unique(M,.. "uniqueNan")</literal> considers all Nan values as the same one,
132 and unduplicates them. By default, any Nan is different
133 from any other Nan, including itself: <literal>%nan<>%nan</literal> is true, unless
134 <literal>"uniqueNan"</literal> is used. Specifying
135 <literal>"uniqueNan"</literal> is case-insensitive.
138 <refsection role="description">
139 <title>Exemplos</title>
140 <para>With some numbers:</para>
141 <programlisting role="example"><![CDATA[
142 M = int8([2 0 2 2 1 1 1 2 1 1 0 1 1 0 1 1
143 0 1 2 0 1 2 2 0 1 1 2 0 1 0 0 0
146 [uc, kmc] = unique(M, "c")
151 2 0 2 2 1 1 1 2 1 1 0 1 1 0 1 1
152 0 1 2 0 1 2 2 0 1 1 2 0 1 0 0 0
154 --> [u, km] = unique(M)
165 --> [uc, kmc] = unique(M, "c")
171 14. 2. 11. 12. 5. 6. 1. 3.
173 <para>With complex numbers:</para>
174 <programlisting role="example"><![CDATA[
176 c = [1+i, 1-i, -i, i, -i, 1+i]
178 [uc, kc] = unique(c, "c")
181 --> c = [1+i, 1-i, -i, i, -i, 1+i]
183 1. + i 1. - i -i i -i 1. + i
185 --> [u, k] = unique(c)
193 <para>With some texts:</para>
194 <programlisting role="example"><![CDATA[
195 t = ["BA" "BB" "AB" "BA" "AB" "BA" "AB" "AB" "BA" "AA" "AB" "BA" "BA" "BA" "AA"
196 "AA" "AB" "AA" "AA" "BB" "BB" "BB" "BA" "AB" "AB" "BB" "BB" "AB" "AB" "AA"
199 [u, kt, ku, nb] = unique(t(1,:))
200 [u, kt] = unique(t(1,:), "keepOrder") // Keeping the original order of row#1 elements
201 [uc, ktc, kuc, nb] = unique(t, "c")
202 [uc, ktc, kuc, nb] = unique(t, "c", "keepOrder") // Keeping the original order of columns
205 --> t = ["BA" "BB" "AB" "BA" "AB" "BA" "AB" "AB" "BA" "AA" "AB" "BA" "BA" "BA" "AA"
206 > "AA" "AB" "AA" "AA" "BB" "BB" "BB" "BA" "AB" "AB" "BB" "BB" "AB" "AB" "AA"
209 !BA BB AB BA AB BA AB AB BA AA AB BA BA BA AA !
210 !AA AB AA AA BB BB BB BA AB AB BB BB AB AB AA !
216 --> [u, kt, ku, nb] = unique(t(1,:))
226 --> [u, kt] = unique(t(1,:), "keepOrder") // Keeping the original order
233 --> [uc, ktc, kuc, nb] = unique(t, "c")
235 !AA AA AB AB AB BA BA BA BB ! Sorted columns
236 !AA AB AA BA BB AA AB BB AB !
239 15. 10. 3. 8. 5. 1. 9. 6. 2.
242 1. 1. 1. 1. 3. 2. 3. 2. 1.
244 --> [uc, ktc, kuc, nb] = unique(t, "c", "keepOrder") // Keeping the original order
246 !BA BB AB AB BA AB BA AA AA !
247 !AA AB AA BB BB BA AB AB AA !
250 1. 2. 3. 5. 6. 8. 9. 10. 15.
253 2. 1. 1. 3. 2. 1. 3. 1. 1.
256 <para>With Nan (and Inf) values. "uniqueNan" option:</para>
257 <programlisting role="example"><![CDATA[
258 M = [2 2 %nan 1 2 0 1 %nan 0 %nan
259 1 0 1 %nan 0 %inf 0 1 %inf 1
261 [v, km, kv, n] = unique(M); v',n'
262 [v, km, kv, n] = unique(M, "uniqueNan"); v',n'
264 [v, kmc, kvc, n] = unique(M, "c", "uniqueNan")
269 2. 2. Nan 1. 2. 0. 1. Nan 0. Nan
270 1. 0. 1. Nan 0. Inf 0. 1. Inf 1.
272 --> [v, km, kv, n] = unique(M); v',n'
274 0. 1. 2. Inf Nan Nan Nan Nan
277 5. 6. 3. 2. 1. 1. 1. 1.
279 --> [v, km, kv, n] = unique(M, "uniqueNan"); v',n'
288 0. 1. 1. 2. 2. Nan Nan Nan
289 Inf 0. Nan 0. 1. 1. 1. 1.
291 --> [v, kmc, kvc, n] = unique(M, "c", "uniqueNan")
303 <refsection role="see also">
304 <title>Ver Também</title>
305 <simplelist type="inline">
307 <link linkend="members">members</link>
310 <link linkend="gsort">gsort</link>
313 <link linkend="vectorfind">vectorfind</link>
316 <link linkend="grep">grep</link>
319 <link linkend="union">union</link>
322 <link linkend="intersect">intersect</link>
326 <refsection role="history">
327 <title>Histórico</title>
330 <revnumber>6.0.2</revnumber>
332 unique() can now be used to unduplicate complex numbers.
336 <revnumber>6.1.0</revnumber>
340 "keepOrder" and "uniqueNan" options introduced.
343 Fourth output argument <literal>nb</literal> introduced.