Main Content

iscategory

确定输入是否为类别的名称

说明

示例

tf = iscategory(A,catnames) 将返回一个包含逻辑值 1 (true) 的数组,其中 catnames 中的数据为 A 类别。否则,iscategory 将返回逻辑值 0 (false)。

tf 的大小与 catnames 相同。

示例

全部折叠

创建一个 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'}

确定衣物的名称 shirtpantssocksshoes 是否属于 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

shirtpantsA 类别,但 socksshoes 不是。

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

输入参数

全部折叠

输入数组,指定为 categorical 数组。

类别名称,指定为字符串数组、字符向量、字符向量元胞数组或 pattern 数组。

扩展功能

版本历史记录

在 R2013b 中推出