removecats
从 categorical
数组中删除类别
说明
示例
删除所有未使用类别
创建一个表示四个人所属政治团体的分类数组。
A = categorical({'republican' 'democrat' 'democrat' 'republican'},... {'democrat' 'republican' 'independent'})
A = 1x4 categorical
republican democrat democrat republican
A
是一个 1×4 分类数组。
汇总分类数组 A
。
summary(A)
democrat republican independent 2 2 0
A
有三个类别。democrat
在数组中出现两次,republican
在数组中出现两次,而未使用 independent
。
删除未使用的类别 independent
。
B = removecats(A)
B = 1x4 categorical
republican democrat democrat republican
B
与 A
的值相同。
显示 B
的类别。
categories(B)
ans = 2x1 cell
{'democrat' }
{'republican'}
B
具有的类别比 A
少。
删除类别以使对应值成为未定义值
创建一个分类数组 A
,其中包含交通方式。
A = categorical({'plane' 'car'; 'train' 'car'; 'plane' 'car'})
A = 3x2 categorical
plane car
train car
plane car
A
是一个 3×2 分类数组。
显示 A
的类别。
categories(A)
ans = 3x1 cell
{'car' }
{'plane'}
{'train'}
A
包含三个类别:car
、plane
和 train
。
删除类别 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
少。
使用模式指定类别
创建一个 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'}
输入参数
提示
对于
A
的任何未使用的类别,~ismember(categories(A),unique(A))
返回逻辑值1
(true
)。
扩展功能
tall 数组
对行数太多而无法放入内存的数组进行计算。
C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。
基于线程的环境
使用 MATLAB® backgroundPool
在后台运行代码或使用 Parallel Computing Toolbox™ ThreadPool
加快代码运行速度。
此函数完全支持基于线程的环境。有关详细信息,请参阅在基于线程的环境中运行 MATLAB 函数。
分布式数组
使用 Parallel Computing Toolbox™ 在集群的组合内存中对大型数组进行分区。
此函数完全支持分布式数组。有关详细信息,请参阅Run MATLAB Functions with Distributed Arrays (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)