categories
分类数组中的类别列表
说明
示例
返回类别列表
使用 categorical
函数创建一个分类数组。
A = categorical(["plane","car","train","car","plane"])
A = 1x5 categorical
plane car train car plane
要返回 A
中的类别的列表,请使用 categories
函数。类别的顺序是在您创建 A
时确定的。如果在使用 categorical
时没有指定顺序,则 categorical
调用 unique
函数来确定输入数组中类别的顺序。
C = categories(A)
C = 3x1 cell
{'car' }
{'plane'}
{'train'}
以分类数组形式返回列表
创建一个分类数组。
A = categorical(["plane","car","train","car","plane"])
A = 1x5 categorical
plane car train car plane
要以分类数组形式返回类别列表,请指定 OutputType
名称-值参量。
C = categories(A,OutputType="categorical")
C = 3x1 categorical
car
plane
train
有序分类数组中的类别
创建一个有序分类数组。将类别的顺序指定为数学排序 small < medium < large
。
A = categorical(["medium";"large";"small";"small";"small";"large"], ... ["small","medium","large"], ... Ordinal=true)
A = 6x1 categorical
medium
large
small
small
small
large
返回有序分类数组中类别的列表。类别按照您在创建该分类数组时指定的顺序出现。
C = categories(A)
C = 3x1 cell
{'small' }
{'medium'}
{'large' }
输入参数
A
— 输入数组
分类数组
输入数组,指定为分类数组。
type
— 输出数据类型
"char"
(默认) | "string"
| "categorical"
输出数据类型,指定为下列选项之一:
"char"
- 返回字符向量元胞数组。如果指定"char"
,则输出等效于第一种语法的输出。"string"
- 返回字符串数组。"categorical"
- 返回分类数组。
提示
C
中列出的类别的顺序与您可以对A
调用的函数(例如summary
和histogram
)使用的顺序相同。要更改类别的顺序,请使用reordercats
。
扩展功能
tall 数组
对行数太多而无法放入内存的数组进行计算。
C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。
此函数完全支持代码生成。有关详细信息,请参阅Code Generation for Categorical Arrays (MATLAB Coder)。
基于线程的环境
使用 MATLAB® backgroundPool
在后台运行代码或使用 Parallel Computing Toolbox™ ThreadPool
加快代码运行速度。
此函数完全支持基于线程的环境。有关详细信息,请参阅在基于线程的环境中运行 MATLAB 函数。
分布式数组
使用 Parallel Computing Toolbox™ 在集群的组合内存中对大型数组进行分区。
用法说明和限制:
不支持
OutputType
名称-值参量。
有关详细信息,请参阅Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox)。
版本历史记录
在 R2013b 中推出R2024a: 以分类数组或字符串数组形式返回类别列表
使用 categories
函数时,您可以指定 OutputType
名称-值参量以便以分类数组或字符串数组返回类别列表。默认情况下,该函数以字符向量元胞数组形式返回类别列表。
另请参阅
categorical
| unique
| addcats
| removecats
| iscategory
| mergecats
| renamecats
| reordercats
| histogram
| 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)