Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.0.2 - 日本語

Change language to:
English - Français - Português - Русский

Please note that the recommended version of Scilab is 2024.0.0. This page might be outdated.
See the recommended documentation of this function

Scilabヘルプ >> Elementary Functions > setoperations > unique

unique

ベクトルまたは行列のユニークなな要素を展開

呼び出し手順

N = unique(M)
N = unique(M, orient)
[N, k] = unique(..)

引数

M

数値または文字列のベクトルまたは行列

orient

フラグで以下の値のどれかとなる : 1 または "r", 2 または "c". It can't be used if M is an hypermatrix.

N

  • If orient is not used: Vector of extracted M components sorted in ascending order.
  • If orient is used: Matrix of extracted M rows or columns, sorted in lexicographic ascending order.

k

Vector of indices of first encountered occurences, such that N(i) = M(k(i)) or N(i,:) = M(k(i),:) or N(:,i) = M(:,k(i)).

説明

unique(M)Mのユニークなエントリを昇順に したものを保持するベクトルを返します.

unique(M,"r") または unique(M,1)は, Mのユニークな行を 辞書式の昇順にして返します.

unique(M,"c") または unique(M,2)Mのユニークな列を 辞書式の昇順にして返します.

Extracted components, rows or columns can be resorted in their initial order by sorting k. See the first example.

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, k] = unique(M)
[uc, kc] = unique(M, "c")

// Get unduplicated columns in initial order:
M(:, gsort(kc,"g","i"))
--> 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, k] = unique(M)
 u  =
  0
  1
  2

 k  =
   2.
   4.
   1.

--> [uc, kc] = unique(M, "c")
 uc  =
  0  0  0  1  1  1  2  2
  0  1  2  0  1  2  0  2

 kc  =
   14.   2.   11.   12.   5.   6.   1.   3.

--> // Get unduplicated columns in initial order:
--> M(:, gsort(kc,"g","i"))
 ans  =
  2  0  2  1  1  0  1  0
  0  1  2  1  2  2  0  0

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 = ["AB" "BA" "BA" "BA" "AB" "BA" "AB" "AB" "BB" "AA" "AB" "BA" "BA" "BA" "AA"
     "AA" "AA" "AB" "AA" "BB" "BB" "BB" "BA" "AB" "AB" "BB" "BB" "AB" "AB" "AA"
    ]
[u, k] = unique(t)
[uc, kc] = unique(t, "c")
 t  =
!AB  BA  BA  BA  AB  BA  AB  AB  BB  AA  AB  BA  BA  BA  AA  !
!AA  AA  AB  AA  BB  BB  BB  BA  AB  AB  BB  BB  AB  AB  AA  !

--> [u, k] = unique(t);
 u  =
!AA  !
!AB  !
!BA  !
!BB  !

 k  =
   2.
   1.
   3.
   10.

--> [uc, kc] = unique(t, "c")
 uc  =
!AA  AA  AB  AB  AB  BA  BA  BA  BB  !
!AA  AB  AA  BA  BB  AA  AB  BB  AB  !

 kc  =
   15.   10.   1.   8.   5.   2.   3.   6.   9.

参照

  • members — 配列の各要素または他の配列の行または列を数える(及び位置を調べる)
  • gsort — クイックソートアルゴリズムによるソート
  • vectorfind — ベクトルに一致する行列の行または列を見つける
  • grep — 文字列のベクトルの中で指定した文字列に一致するかどうかを調べる
  • union — ベクトルの和集合要素を展開
  • intersect — returns the unduplicated elements or rows or columns met in both input arrays

履歴

バージョン記述
6.0.2 unique() can now be used to unduplicate complex numbers.
Report an issue
<< union setoperations signalprocessing >>

Copyright (c) 2022-2023 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu Feb 14 15:02:07 CET 2019