メインコンテンツ

addcats

categorical 配列へのカテゴリの追加

説明

B = addcats(A,newcats) は、カテゴリを categorical 配列に追加します。既定では、categories(A) の出力に示されているように、addcats は新しいカテゴリをカテゴリ セットの末尾に追加します。新しい要素は追加されません。新しいカテゴリのいずれかに属する要素を B に代入するまで、出力の categorical 配列 B には、そのような要素は含まれません。

A が順序 categorical 配列である場合は、名前と値の引数 Before または After を指定しなければなりません。

B = addcats(A,newcats,Before=catname) は、指定されたカテゴリの前にカテゴリを追加します。

B = addcats(A,newcats,After=catname) は、指定されたカテゴリの後にカテゴリを追加します。

すべて折りたたむ

categorical 配列を作成します。

A = categorical(["red" "blue" "red" "blue" "red" "blue"])
A = 1×6 categorical
     red      blue      red      blue      red      blue 

配列のカテゴリを表示します。

categories(A)
ans = 2×1 cell
    {'blue'}
    {'red' }

カテゴリ green および black を、カテゴリ セットの末尾に追加します。新しい配列には同じ要素が含まれていますが、より多くのカテゴリがあります。

B = addcats(A,["green" "black"])
B = 1×6 categorical
     red      blue      red      blue      red      blue 

categories(B)
ans = 4×1 cell
    {'blue' }
    {'red'  }
    {'green'}
    {'black'}

順序 categorical 配列を作成します。

A = categorical(["medium" "large"; "small" "xlarge"; "large" "medium"], ...
                ["small" "medium" "large" "xlarge"], ...
                Ordinal=true)
A = 3×2 categorical
     medium      large  
     small       xlarge 
     large       medium 

そのカテゴリを表示します。A は順序配列であるため、カテゴリは数学的な順序 small < medium < large < xlarge をもちます。

categories(A)
ans = 4×1 cell
    {'small' }
    {'medium'}
    {'large' }
    {'xlarge'}

カテゴリ xsmallsmall の前に追加します。次に、新しい配列のカテゴリを表示します。カテゴリは、数学的な順序 xsmall < small < medium < large < xlarge になります。

B = addcats(A,"xsmall",Before="small");
categories(B)
ans = 5×1 cell
    {'xsmall'}
    {'small' }
    {'medium'}
    {'large' }
    {'xlarge'}

入力引数

すべて折りたたむ

入力配列。categorical 配列として指定します。

新規カテゴリ。string 配列、文字ベクトル、または文字ベクトルの cell 配列として指定します。

カテゴリの名前。string スカラーまたは文字ベクトルとして指定します。

拡張機能

すべて展開する

C/C++ コード生成
MATLAB® Coder™ を使用して C および C++ コードを生成します。

バージョン履歴

R2013b で導入