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:ns5="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="ja">
21 <refname>unique</refname>
22 <refpurpose>ベクトルまたは行列のユニークなな要素を展開</refpurpose>
27 [U, km, ku, nb] = unique(M)
28 [U, km, ku, nb] = unique(M, orient)
29 [U, km, ku, nb] = unique(.., "keepOrder")
30 [U, km, ku, nb] = unique(.., "uniqueNan")
33 <refsection role="parameters">
40 vector, matrix, or hypermatrix of booleans, numbers, or strings.
47 <para>フラグで以下の値のどれかとなる : 1 または "r", 2 または "c".
48 It can't be used if <varname>M</varname> is an hypermatrix.
59 If <varname>orient</varname> is not used: Vector of extracted
60 <varname>M</varname> components sorted in ascending order.
61 If <varname>M</varname> is a row vector, <varname>U</varname> is also
62 a row vector. In all other <varname>M</varname> cases,
63 <varname>U</varname> is a column vector.
67 If <varname>orient</varname> is used: Matrix of extracted
68 <varname>M</varname> rows or columns, sorted in lexicographic ascending order.
77 Vector of indices of first encountered occurrences, such that
78 <literal>U = M(km)</literal> or <literal>U = M(km,:)</literal>
79 or <literal>U = M(:,km)</literal>.
81 <varname>km</varname> is a row if <varname>M</varname> is a row or if
82 <literal>orient="c"</literal> is used. Otherwise it's a column.
89 Array of indices in U, such that, according to the <varname>orient</varname> option
92 "*": <varname>ku</varname> is of size size(M), and <literal>U(ku) = M</literal>
95 "r": <varname>ku</varname> is of size [size(M,1), 1], and <literal>U(ku,:) = M</literal>
98 "c": <varname>ku</varname> is of size [1, size(M,2)], and <literal>U(:,ku) = M</literal>
108 Vector of integers > 0, with the same <varname>km</varname> shape:
109 Numbers of occurences in <varname>M</varname> of respective unduplicated
110 entities (components, rows, columns) returned in <varname>U</varname>.
116 <refsection role="description">
119 <literal>unique(M)</literal> は
120 <literal>M</literal>のユニークなエントリを昇順に
124 <literal>unique(M,"r")</literal> または
125 <literal>unique(M,1)</literal>は,
126 <literal>M</literal>のユニークな行を
130 <literal>unique(M,"c")</literal> または
131 <literal>unique(M,2)</literal>は
132 <literal>M</literal>のユニークな列を
136 <literal>unique(M,.. "keepOrder")</literal> returns <varname>M</varname> unduplicated
137 entries in their original order in <varname>M</varname>.
138 <literal>"keepOrder"</literal> is case-insensitive.
141 <literal>unique(M,.. "uniqueNan")</literal> considers all Nan values as the same one,
142 and unduplicates them. By default, any Nan is different
143 from any other Nan, including itself: <literal>%nan<>%nan</literal> is true, unless
144 <literal>"uniqueNan"</literal> is used. Specifying
145 <literal>"uniqueNan"</literal> is case-insensitive.
148 For booleans, <literal>unique(…)</literal> is useful mainly with the "r" or "c" options.
152 Complex numbers are sorted first by increasing magnitudes, then by increasing
157 <refsection role="examples">
159 <para>With some numbers:</para>
160 <programlisting role="example"><![CDATA[
161 M = int8([2 0 2 2 1 1 1 2 1 1 0 1 1 0 1 1
162 0 1 2 0 1 2 2 0 1 1 2 0 1 0 0 0
165 [uc, kmc] = unique(M, "c")
170 2 0 2 2 1 1 1 2 1 1 0 1 1 0 1 1
171 0 1 2 0 1 2 2 0 1 1 2 0 1 0 0 0
173 --> [u, km] = unique(M)
184 --> [uc, kmc] = unique(M, "c")
190 14. 2. 11. 12. 5. 6. 1. 3.
192 <para>With complex numbers:</para>
193 <programlisting role="example"><![CDATA[
195 c = [1+i, 1-i, -i, i, -i, 1+i]
197 [uc, kc] = unique(c, "c")
200 --> c = [1+i, 1-i, -i, i, -i, 1+i]
202 1. + i 1. - i 0. - i 0. + i 0. - i 1. + i
204 --> [u, k] = unique(c)
206 0. - i 0. + i 1. - i 1. + i
210 --> [uc, kc] = unique(c, "c")
212 0. - i 0. + i 1. - i 1. + i
217 <para>With some texts:</para>
218 <programlisting role="example"><![CDATA[
219 t = ["BA" "BB" "AB" "BA" "AB" "BA" "AB" "AB" "BA" "AA" "AB" "BA" "BA" "BA" "AA"
220 "AA" "AB" "AA" "AA" "BB" "BB" "BB" "BA" "AB" "AB" "BB" "BB" "AB" "AB" "AA"
223 [u, kt, nb] = unique(t(1,:))
224 [u, kt] = unique(t(1,:), "keepOrder") // In original order of row#1 elements
225 [uc, ktc, kuc, nb] = unique(t, "c")
226 [uc, ktc, kuc, nb] = unique(t, "c", "keepOrder") // In original order of columns
227 [and(t(:,ktc)==uc), and(uc(:,kuc)==t) ]
230 --> t = ["BA" "BB" "AB" "BA" "AB" "BA" "AB" "AB" "BA" "AA" "AB" "BA" "BA" "BA" "AA"
231 > "AA" "AB" "AA" "AA" "BB" "BB" "BB" "BA" "AB" "AB" "BB" "BB" "AB" "AB" "AA"
234 !BA BB AB BA AB BA AB AB BA AA AB BA BA BA AA !
235 !AA AB AA AA BB BB BB BA AB AB BB BB AB AB AA !
241 --> [u, kt, ku, nb] = unique(t(1,:))
251 --> [u, kt] = unique(t(1,:), "keepOrder") // Keeping the original order
258 --> [uc, ktc, kuc, nb] = unique(t, "c")
260 !AA AA AB AB AB BA BA BA BB ! Sorted columns
261 !AA AB AA BA BB AA AB BB AB !
264 15. 10. 3. 8. 5. 1. 9. 6. 2.
267 1. 1. 1. 1. 3. 2. 3. 2. 1.
269 --> [uc, kc, nb] = unique(t, "c", "keepOrder") // Keeping the original order
271 !BA BB AB AB BA AB BA AA AA !
272 !AA AB AA BB BB BA AB AB AA !
275 1. 2. 3. 5. 6. 8. 9. 10. 15.
278 2. 1. 1. 3. 2. 1. 3. 1. 1.
280 --> [and(t(:,ktc)==uc), and(uc(:,kuc)==t) ]
285 <para>With Nan (and Inf) values. "uniqueNan" option:</para>
286 <programlisting role="example"><![CDATA[
287 M = [2 2 %nan 1 2 0 1 %nan 0 %nan
288 1 0 1 %nan 0 %inf 0 1 %inf 1
290 [v, km, kv, n] = unique(M); v',n'
291 [v, km, kv, n] = unique(M, "uniqueNan"); v',n'
293 [v, kmc, kvc, n] = unique(M, "c", "uniqueNan")
298 2. 2. Nan 1. 2. 0. 1. Nan 0. Nan
299 1. 0. 1. Nan 0. Inf 0. 1. Inf 1.
301 --> [v, km, kv, n] = unique(M); v',n'
303 0. 1. 2. Inf Nan Nan Nan Nan
306 5. 6. 3. 2. 1. 1. 1. 1.
308 --> [v, km, kv, n] = unique(M, "uniqueNan"); v',n'
317 0. 1. 1. 2. 2. Nan Nan Nan
318 Inf 0. Nan 0. 1. 1. 1. 1.
320 --> [v, kmc, kvc, n] = unique(M, "c", "uniqueNan")
332 <refsection role="see also">
334 <simplelist type="inline">
336 <link linkend="members">members</link>
339 <link linkend="gsort">gsort</link>
342 <link linkend="vectorfind">vectorfind</link>
345 <link linkend="grep">grep</link>
348 <link linkend="union">union</link>
351 <link linkend="intersect">intersect</link>
355 <refsection role="history">
359 <revnumber>6.0.2</revnumber>
361 unique() can now be used to unduplicate complex numbers.
365 <revnumber>6.1.0</revnumber>
369 Extension to booleans.
372 "keepOrder" and "uniqueNan" options introduced.
375 Fourth output argument <literal>nb</literal> introduced.
381 <revnumber>6.1.1</revnumber>
383 ku 3rd output implemented.