Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
See the recommended documentation of this function
unique
ベクトルまたは行列のユニークなな要素を展開
呼び出し手順
[N, km, kn, nb] = unique(M) [N, km, kn, nb] = unique(M, orient) [N, km, kn, nb] = unique(.., "keepOrder") [N, km, kn, nb] = unique(.., "uniqueNan")
引数
- M
数値または文字列のベクトルまたは行列
- orient
フラグで以下の値のどれかとなる : 1 または "r", 2 または "c". It can't be used if
M
is an hypermatrix.- N
If
orient
is not used: Vector of extractedM
components sorted in ascending order. IfM
is a row vector,N
is also a row vector. In all otherM
cases,N
is a matrix or a column vector.- If
orient
is used: Matrix of extractedM
rows or columns, sorted in lexicographic ascending order.
- k
Vector of indices of first encountered occurences, such that
N(i) = M(k(i))
orN(i,:) = M(k(i),:)
orN(:,i) = M(:,k(i))
.k
is a row ifM
is a row or iforient="c"
is used. Otherwise it's a column.- kn
- Not yet implemented.
Vector of indices of first encountered occurrences, such that
M(i) = N(kn(i))
orM(i,:) = N(kn(i),:)
orM(:,i) = N(:,kn(i))
. - nb
Vector of integers > 0, with the same
k
shape: Numbers of occurences inM
of respective unduplicated entities (components, rows, columns) returned inN
.
説明
unique(M)
は
M
のユニークなエントリを昇順に
したものを保持するベクトルを返します.
unique(M,"r")
または
unique(M,1)
は,
M
のユニークな行を
辞書式の昇順にして返します.
unique(M,"c")
または
unique(M,2)
は
M
のユニークな列を
辞書式の昇順にして返します.
unique(M,.. "keepOrder")
returns M
unduplicated
entries in their original order in M
.
"keepOrder"
is case-insensitive.
unique(M,.. "uniqueNan")
considers all Nan values as the same one,
and unduplicates them. By default, any Nan is different
from any other Nan, including itself: %nan<>%nan
is true, unless
"uniqueNan"
is used. Specifying
"uniqueNan"
is case-insensitive.
例
With some numbers:
M = int8([2 0 2 2 1 1 1 2 1 1 0 1 1 0 1 1 0 1 2 0 1 2 2 0 1 1 2 0 1 0 0 0 ]) [u, km] = unique(M) [uc, kmc] = unique(M, "c")
--> M M = 2 0 2 2 1 1 1 2 1 1 0 1 1 0 1 1 0 1 2 0 1 2 2 0 1 1 2 0 1 0 0 0 --> [u, km] = unique(M) u = 0 1 2 km = 2. 4. 1. --> [uc, kmc] = unique(M, "c") uc = 0 0 0 1 1 1 2 2 0 1 2 0 1 2 0 2 kmc = 14. 2. 11. 12. 5. 6. 1. 3.
With complex numbers:
i = %i; c = [1+i, 1-i, -i, i, -i, 1+i] [u, k] = unique(c) [uc, kc] = unique(c, "c")
--> c = [1+i, 1-i, -i, i, -i, 1+i] c = 1. + i 1. - i -i i -i 1. + i --> [u, k] = unique(c) u = -i i 1. - i 1. + i k = 3. 4. 2. 1.
With some texts:
t = ["BA" "BB" "AB" "BA" "AB" "BA" "AB" "AB" "BA" "AA" "AB" "BA" "BA" "BA" "AA" "AA" "AB" "AA" "AA" "BB" "BB" "BB" "BA" "AB" "AB" "BB" "BB" "AB" "AB" "AA" ] u = unique(t)' [u, kt, nb] = unique(t(1,:)) [u, kt] = unique(t(1,:), "keepOrder") // Keeping the original order of row#1 elements [uc, ktc, kuc, nb] = unique(t, "c") [uc, ktc, kuc, nb] = unique(t, "c", "keepOrder") // Keeping the original order of columns
--> t = ["BA" "BB" "AB" "BA" "AB" "BA" "AB" "AB" "BA" "AA" "AB" "BA" "BA" "BA" "AA" > "AA" "AB" "AA" "AA" "BB" "BB" "BB" "BA" "AB" "AB" "BB" "BB" "AB" "AB" "AA" > ] t = !BA BB AB BA AB BA AB AB BA AA AB BA BA BA AA ! !AA AB AA AA BB BB BB BA AB AB BB BB AB AB AA ! --> u = unique(t)' u = !AA AB BA BB ! --> [u, kt, ku, nb] = unique(t(1,:)) u = !AA AB BA BB ! kt = 10. 3. 1. 2. nb = 2. 5. 7. 1. --> [u, kt] = unique(t(1,:), "keepOrder") // Keeping the original order u = !BA BB AB AA ! kt = 1. 2. 3. 10. --> [uc, ktc, kuc, nb] = unique(t, "c") uc = !AA AA AB AB AB BA BA BA BB ! Sorted columns !AA AB AA BA BB AA AB BB AB ! ktc = 15. 10. 3. 8. 5. 1. 9. 6. 2. nb = 1. 1. 1. 1. 3. 2. 3. 2. 1. --> [uc, kc, nb] = unique(t, "c", "keepOrder") // Keeping the original order uc = !BA BB AB AB BA AB BA AA AA ! !AA AB AA BB BB BA AB AB AA ! kc = 1. 2. 3. 5. 6. 8. 9. 10. 15. nb = 2. 1. 1. 3. 2. 1. 3. 1. 1.
With Nan (and Inf) values. "uniqueNan" option:
M = [2 2 %nan 1 2 0 1 %nan 0 %nan 1 0 1 %nan 0 %inf 0 1 %inf 1 ]; [v, km, kv, n] = unique(M); v',n' [v, km, kv, n] = unique(M, "uniqueNan"); v',n' unique(M, "c") [v, kmc, kvc, n] = unique(M, "c", "uniqueNan")
--> M M = 2. 2. Nan 1. 2. 0. 1. Nan 0. Nan 1. 0. 1. Nan 0. Inf 0. 1. Inf 1. --> [v, km, kv, n] = unique(M); v',n' ans = 0. 1. 2. Inf Nan Nan Nan Nan ans = 5. 6. 3. 2. 1. 1. 1. 1. --> [v, km, kv, n] = unique(M, "uniqueNan"); v',n' ans = 0. 1. 2. Inf Nan ans = 5. 6. 3. 2. 4. --> unique(M, "c") ans = 0. 1. 1. 2. 2. Nan Nan Nan Inf 0. Nan 0. 1. 1. 1. 1. --> [v, kmc, kvc, n] = unique(M, "c", "uniqueNan") v = 0. 1. 1. 2. 2. Nan Inf 0. Nan 0. 1. 1. kmc = 6. 7. 4. 2. 1. 3. n = 2. 1. 1. 2. 1. 3.
参照
- members — 配列の各要素または他の配列の行または列を数える(及び位置を調べる)
- gsort — sorting by quick sort algorithm
- vectorfind — locates occurences of a (wildcarded) vector in a matrix or hypermatrix
- grep — 文字列のベクトルの中で指定した文字列に一致するかどうかを調べる
- union — ベクトルの和集合要素を展開
- intersect — returns the unduplicated elements or rows or columns met in both input arrays
履歴
Version | Description |
6.0.2 | unique() can now be used to unduplicate complex numbers. |
6.1.0 |
|
Report an issue | ||
<< union | setoperations | Trigonometry >> |