removecats
categorical
配列からのカテゴリの削除
説明
例
すべての未使用カテゴリの削除
4 人で構成される政党を表す categorical 配列を作成します。
A = categorical({'republican' 'democrat' 'democrat' 'republican'},... {'democrat' 'republican' 'independent'})
A = 1x4 categorical
republican democrat democrat republican
A
は 1 行 4 列の categorical 配列です。
categorical 配列 A
を集計します。
summary(A)
democrat republican independent 2 2 0
A
には 3 つのカテゴリがあります。democrat
と republican
は配列に 2 回表示され、independent
は未使用です。
未使用カテゴリ independent
を削除します。
B = removecats(A)
B = 1x4 categorical
republican democrat democrat republican
B
の値は A
と同じです。
B
のカテゴリを表示します。
categories(B)
ans = 2x1 cell
{'democrat' }
{'republican'}
B
のカテゴリ数は A
より少なくなります。
カテゴリを削除して対応する値を未定義にする
交通手段を含む categorical 配列 A
を作成します。
A = categorical({'plane' 'car'; 'train' 'car'; 'plane' 'car'})
A = 3x2 categorical
plane car
train car
plane car
A
は 3 行 2 列の categorical 配列です。
A
のカテゴリを表示します。
categories(A)
ans = 3x1 cell
{'car' }
{'plane'}
{'train'}
A
には、car
、plane
、train
の 3 つのカテゴリがあります。
カテゴリ train
を削除します。
B = removecats(A,'train')
B = 3x2 categorical
plane car
<undefined> car
plane car
カテゴリ train
からの要素は未定義になります。
B
のカテゴリを表示します。
categories(B)
ans = 2x1 cell
{'car' }
{'plane'}
B
のカテゴリ数は A
より 1 つ少なくなります。
パターンを使用したカテゴリの指定
categorical
配列を作成します。この配列には、"はい" と "いいえ" を表すさまざまなカテゴリがあります。
C = categorical(["Y","Yes","N","No","Yes","Y"])
C = 1x6 categorical
Y Yes N No Yes Y
categories(C)
ans = 4x1 cell
{'N' }
{'No' }
{'Y' }
{'Yes'}
pattern
を使用すると、複数のカテゴリ名を一致させることができます。たとえば、Y
で始まるカテゴリ名を指定するには、ワイルドカード パターンを使用できます。ワイルドカード パターンを作成するには、関数wildcardPattern
を使用します。
名前が Y
で始まるカテゴリを削除します。関数 removecats
はカテゴリを削除しますが、入力配列の要素は削除しません。そのため、名前が Y
で始まるカテゴリに属する要素は未定義値となります。
C = removecats(C,"Y"+wildcardPattern)
C = 1x6 categorical
<undefined> <undefined> N No <undefined> <undefined>
categories(C)
ans = 2x1 cell
{'N' }
{'No'}
入力引数
ヒント
~ismember(categories(A),unique(A))
は、A
の未使用カテゴリに対して logical1
(true
) を返します。
拡張機能
tall 配列
メモリの許容量を超えるような多数の行を含む配列を計算します。
C/C++ コード生成
MATLAB® Coder™ を使用して C および C++ コードを生成します。
スレッドベースの環境
MATLAB® の backgroundPool
を使用してバックグラウンドでコードを実行するか、Parallel Computing Toolbox™ の ThreadPool
を使用してコードを高速化します。
この関数はスレッドベースの環境を完全にサポートしています。詳細については、スレッドベースの環境での MATLAB 関数の実行を参照してください。
分散配列
Parallel Computing Toolbox™ を使用して、クラスターの結合メモリ上で大きなアレイを分割します。
この関数は分散配列を完全にサポートしています。詳細については、分散配列を使用した MATLAB 関数の実行 (Parallel Computing Toolbox)を参照してください。
バージョン履歴
R2013b で導入
参考
categories
| summary
| addcats
| iscategory
| mergecats
| renamecats
| reordercats
| setcats
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)