Main Content

addcats

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

説明

B = addcats(A,newcats) は、入力 categorical 配列 A のカテゴリ リストの末尾にカテゴリを追加します。出力 categorical 配列 B には、A と同じ値が含まれます。出力 B は、newcats から B の要素へ値が代入されない限り、新しいカテゴリと等しい要素を含みません。

A が順序 categorical 配列である場合は、'Before',beforewhere または 'After',afterwhere 入力引数を指定しなければなりません。

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

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

すべて折りたたむ

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

A = categorical({'republican' 'democrat' 'republican';...
    'democrat' 'republican' 'democrat'})
A = 2x3 categorical
     republican      democrat        republican 
     democrat        republican      democrat   

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

categories(A)
ans = 2x1 cell
    {'democrat'  }
    {'republican'}

A は、2 つのカテゴリをもつ 2 行 3 列の categorical 配列です。

カテゴリ independent および undeclared を、カテゴリ リストの末尾に追加します。

B = addcats(A,{'independent' 'undeclared'})
B = 2x3 categorical
     republican      democrat        republican 
     democrat        republican      democrat   

B は、A と同じ値を含みます。

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

categories(B)
ans = 4x1 cell
    {'democrat'   }
    {'republican' }
    {'independent'}
    {'undeclared' }

B は、4 つのカテゴリをもつ 2 行 3 列の categorical 配列です。

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

A = categorical({'medium' 'large'; 'small' 'xlarge'; 'large' 'medium'},...
    {'small' 'medium' 'large' 'xlarge'},'Ordinal',true)
A = 3x2 categorical
     medium      large  
     small       xlarge 
     large       medium 

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

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

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

カテゴリ xsmallsmall の前に追加します。

B = addcats(A,'xsmall','Before','small')
B = 3x2 categorical
     medium      large  
     small       xlarge 
     large       medium 

B は、A と同じ値を含みます。

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

categories(B)
ans = 5x1 cell
    {'xsmall'}
    {'small' }
    {'medium'}
    {'large' }
    {'xlarge'}

カテゴリは、数学的な順序 xsmall < small < medium < large < xlarge になります。

入力引数

すべて折りたたむ

categorical 配列。ベクトル、行列または多次元配列として指定します。

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

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

後に続くカテゴリ。文字ベクトルまたは string スカラーとして指定します。

拡張機能

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

バージョン履歴

R2013b で導入