addcats
将类别添加到分类数组
语法
说明
B = addcats(
在 A
,newcats
,'Before',beforewhere
)beforewhere
指定的类别前添加类别。
B = addcats(
在 A
,newcats
,'After',afterwhere
)afterwhere
指定的类别后添加类别。
示例
在末尾添加新类别
创建非有序分类数组。
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×3 分类数组。
将类别 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
是一个有四个类别的 2×3 分类数组。
添加类别并指定置于什么类别之前
创建一个有序分类数组。
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
。
将类别 xsmall
添加到 small
之前。
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
。
输入参数
A
— 分类数组
向量 | 矩阵 | 多维数组
分类数组,指定为向量、矩阵或多维数组。
newcats
— 新类别
字符向量 | 字符向量元胞数组 | 字符串数组
新类别,指定为字符向量、字符向量元胞数组或字符串数组。
beforewhere
— 前导类别
字符向量 | 字符串标量
前导类别,指定为字符向量或字符串标量。
afterwhere
— 后续类别
字符向量 | 字符串标量
后续类别,指定为字符向量或字符串标量。
扩展功能
tall 数组
对行数太多而无法放入内存的数组进行计算。
此函数完全支持 tall 数组。有关详细信息,请参阅 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
| removecats
| 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)