iscategory
确定输入是否为类别的名称
说明
示例
确定名称是否为属于指定类别
创建一个 categorical
数组 A
。
A = categorical(["shirt","pants"; "pants","hat"; "shirt","pants"])
A = 3x2 categorical
shirt pants
pants hat
shirt pants
A
的类别是衣物的名称。它们来自输入数组的唯一值。
categories(A)
ans = 3x1 cell
{'hat' }
{'pants'}
{'shirt'}
确定衣物的名称 shirt
、pants
、socks
和 shoes
是否属于 A
的类别。
catnames = ["shirt","pants","socks","shoes"]
catnames = 1x4 string
"shirt" "pants" "socks" "shoes"
tf = iscategory(A,catnames)
tf = 1x4 logical array
1 1 0 0
shirt
和 pants
是 A
类别,但 socks
和 shoes
不是。
iscategory
没有提供有关类别 hat
的任何信息,因为未将其包含在 catnames
中。
测试无相应数据的类别
创建一个 categorical
数组 A
。
data = ["plane","car","train","car","plane"]; categoriesOfData = ["boat","car","plane","train"]; A = categorical(data,categoriesOfData)
A = 1x5 categorical
plane car train car plane
确定 boat
是否属于 A
中的类别。
tf = iscategory(A,"boat")
tf = logical
1
iscategory
返回 1
(true),即使 A
不包含类别 boat
中的任何值也是如此。
使用模式匹配类别名称
创建一个 categorical
数组。
C = categorical(["Y" "Yes" "Yeah" "N" "No" "Nope"])
C = 1x6 categorical
Y Yes Yeah N No Nope
您可以使用pattern
匹配一个或多个类别名称。例如,通过使用通配符模式来确定是否有以 Y
开头的类别名称。您可以使用 wildcardPattern
函数创建通配符模式。
tf = iscategory(C,"Y" + wildcardPattern)
tf = logical
1
确定是否有以 X
开头的类别名称。
tf = iscategory(C,"X" + wildcardPattern)
tf = logical
0
输入参数
扩展功能
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
| categorical
| removecats
| mergecats
| renamecats
| reordercats
| ismember
| unique
| setcats
| addcats
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)