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 [N, km, kn, nb] = unique(M)
28 [N, km, kn, nb] = unique(M, orient)
29 [N, km, kn, nb] = unique(.., "keepOrder")
30 [N, km, kn, nb] = unique(.., "uniqueNan")
33 <refsection role="parameters">
39 <para>数値または文字列のベクトルまたは行列</para>
45 <para>フラグで以下の値のどれかとなる : 1 または "r", 2 または "c".
46 It can't be used if <varname>M</varname> is an hypermatrix.
57 If <varname>orient</varname> is not used: Vector of extracted
58 <varname>M</varname> components sorted in ascending order.
59 If <varname>M</varname> is a row vector, <varname>N</varname> is also
60 a row vector. In all other <varname>M</varname> cases,
61 <varname>N</varname> is a matrix or a column vector.
65 If <varname>orient</varname> is used: Matrix of extracted
66 <varname>M</varname> rows or columns, sorted in lexicographic ascending order.
76 Vector of indices of first encountered occurences, such that
77 <literal>N(i) = M(k(i))</literal> or <literal>N(i,:) = M(k(i),:)</literal>
78 or <literal>N(:,i) = M(:,k(i))</literal>.
81 <varname>k</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.
90 Vector of indices of first encountered occurrences, such that
91 <literal>M(i) = N(kn(i))</literal> or <literal>M(i,:) = N(kn(i),:)</literal>
92 or <literal>M(:,i) = N(:,kn(i))</literal>.
100 Vector of integers > 0, with the same <varname>k</varname> shape:
101 Numbers of occurences in <varname>M</varname> of respective unduplicated
102 entities (components, rows, columns) returned in <varname>N</varname>.
108 <refsection role="description">
111 <literal>unique(M)</literal> は
112 <literal>M</literal>のユニークなエントリを昇順に
116 <literal>unique(M,"r")</literal> または
117 <literal>unique(M,1)</literal>は,
118 <literal>M</literal>のユニークな行を
122 <literal>unique(M,"c")</literal> または
123 <literal>unique(M,2)</literal>は
124 <literal>M</literal>のユニークな列を
128 <literal>unique(M,.. "keepOrder")</literal> returns <varname>M</varname> unduplicated
129 entries in their original order in <varname>M</varname>.
130 <literal>"keepOrder"</literal> is case-insensitive.
133 <literal>unique(M,.. "uniqueNan")</literal> considers all Nan values as the same one,
134 and unduplicates them. By default, any Nan is different
135 from any other Nan, including itself: <literal>%nan<>%nan</literal> is true, unless
136 <literal>"uniqueNan"</literal> is used. Specifying
137 <literal>"uniqueNan"</literal> is case-insensitive.
140 <refsection role="examples">
142 <para>With some numbers:</para>
143 <programlisting role="example"><![CDATA[
144 M = int8([2 0 2 2 1 1 1 2 1 1 0 1 1 0 1 1
145 0 1 2 0 1 2 2 0 1 1 2 0 1 0 0 0
148 [uc, kmc] = unique(M, "c")
153 2 0 2 2 1 1 1 2 1 1 0 1 1 0 1 1
154 0 1 2 0 1 2 2 0 1 1 2 0 1 0 0 0
156 --> [u, km] = unique(M)
167 --> [uc, kmc] = unique(M, "c")
173 14. 2. 11. 12. 5. 6. 1. 3.
175 <para>With complex numbers:</para>
176 <programlisting role="example"><![CDATA[
178 c = [1+i, 1-i, -i, i, -i, 1+i]
180 [uc, kc] = unique(c, "c")
183 --> c = [1+i, 1-i, -i, i, -i, 1+i]
185 1. + i 1. - i -i i -i 1. + i
187 --> [u, k] = unique(c)
195 <para>With some texts:</para>
196 <programlisting role="example"><![CDATA[
197 t = ["BA" "BB" "AB" "BA" "AB" "BA" "AB" "AB" "BA" "AA" "AB" "BA" "BA" "BA" "AA"
198 "AA" "AB" "AA" "AA" "BB" "BB" "BB" "BA" "AB" "AB" "BB" "BB" "AB" "AB" "AA"
201 [u, kt, nb] = unique(t(1,:))
202 [u, kt] = unique(t(1,:), "keepOrder") // Keeping the original order of row#1 elements
203 [uc, ktc, kuc, nb] = unique(t, "c")
204 [uc, ktc, kuc, nb] = unique(t, "c", "keepOrder") // Keeping the original order of columns
207 --> t = ["BA" "BB" "AB" "BA" "AB" "BA" "AB" "AB" "BA" "AA" "AB" "BA" "BA" "BA" "AA"
208 > "AA" "AB" "AA" "AA" "BB" "BB" "BB" "BA" "AB" "AB" "BB" "BB" "AB" "AB" "AA"
211 !BA BB AB BA AB BA AB AB BA AA AB BA BA BA AA !
212 !AA AB AA AA BB BB BB BA AB AB BB BB AB AB AA !
218 --> [u, kt, ku, nb] = unique(t(1,:))
228 --> [u, kt] = unique(t(1,:), "keepOrder") // Keeping the original order
235 --> [uc, ktc, kuc, nb] = unique(t, "c")
237 !AA AA AB AB AB BA BA BA BB ! Sorted columns
238 !AA AB AA BA BB AA AB BB AB !
241 15. 10. 3. 8. 5. 1. 9. 6. 2.
244 1. 1. 1. 1. 3. 2. 3. 2. 1.
246 --> [uc, kc, nb] = unique(t, "c", "keepOrder") // Keeping the original order
248 !BA BB AB AB BA AB BA AA AA !
249 !AA AB AA BB BB BA AB AB AA !
252 1. 2. 3. 5. 6. 8. 9. 10. 15.
255 2. 1. 1. 3. 2. 1. 3. 1. 1.
258 <para>With Nan (and Inf) values. "uniqueNan" option:</para>
259 <programlisting role="example"><![CDATA[
260 M = [2 2 %nan 1 2 0 1 %nan 0 %nan
261 1 0 1 %nan 0 %inf 0 1 %inf 1
263 [v, km, kv, n] = unique(M); v',n'
264 [v, km, kv, n] = unique(M, "uniqueNan"); v',n'
266 [v, kmc, kvc, n] = unique(M, "c", "uniqueNan")
271 2. 2. Nan 1. 2. 0. 1. Nan 0. Nan
272 1. 0. 1. Nan 0. Inf 0. 1. Inf 1.
274 --> [v, km, kv, n] = unique(M); v',n'
276 0. 1. 2. Inf Nan Nan Nan Nan
279 5. 6. 3. 2. 1. 1. 1. 1.
281 --> [v, km, kv, n] = unique(M, "uniqueNan"); v',n'
290 0. 1. 1. 2. 2. Nan Nan Nan
291 Inf 0. Nan 0. 1. 1. 1. 1.
293 --> [v, kmc, kvc, n] = unique(M, "c", "uniqueNan")
305 <refsection role="see also">
307 <simplelist type="inline">
309 <link linkend="members">members</link>
312 <link linkend="gsort">gsort</link>
315 <link linkend="vectorfind">vectorfind</link>
318 <link linkend="grep">grep</link>
321 <link linkend="union">union</link>
324 <link linkend="intersect">intersect</link>
328 <refsection role="history">
332 <revnumber>6.0.2</revnumber>
334 unique() can now be used to unduplicate complex numbers.
338 <revnumber>6.1.0</revnumber>
342 "keepOrder" and "uniqueNan" options introduced.
345 Fourth output argument <literal>nb</literal> introduced.