Main Content


Determine if inputs are names of categories



tf = iscategory(A,catnames) returns an array containing logical 1 (true) where the data in catnames is a category of A. Otherwise, iscategory returns logical 0 (false).

tf is the same size as catnames.


collapse all

Create a categorical array, A.

A = categorical(["shirt","pants"; "pants","hat"; "shirt","pants"])
A = 3x2 categorical
     shirt      pants 
     pants      hat   
     shirt      pants 

The categories of A are names of articles of clothing. They come from the unique values of the input array.

ans = 3x1 cell
    {'hat'  }

Determine if the names of articles of clothing, shirt, pants, socks, and shoes, are categories of 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 and pants are categories of A, but socks and shoes are not.

iscategory does not tell us anything about the category, hat, which we did not include in catnames.

Create a categorical array, A.

data = ["plane","car","train","car","plane"];
categoriesOfData = ["boat","car","plane","train"];
A = categorical(data,categoriesOfData)
A = 1x5 categorical
     plane      car      train      car      plane 

Determine if boat is a category in A.

tf = iscategory(A,"boat")
tf = logical

iscategory returns 1 (true), even though A does not contain any values from the category boat.

Create a categorical array.

C = categorical(["Y" "Yes" "Yeah" "N" "No" "Nope"])
C = 1x6 categorical
     Y      Yes      Yeah      N      No      Nope 

You can match one or more category names by using a pattern. For example, determine if any category names start with a Y by using a wildcard pattern. You can create a wildcard pattern with the wildcardPattern function.

tf = iscategory(C,"Y" + wildcardPattern)
tf = logical

Determine if any category names start with an X.

tf = iscategory(C,"X" + wildcardPattern)
tf = logical

Input Arguments

collapse all

Input array, specified as a categorical array.

Category names, specified as a string array, character vector, cell array of character vectors, or pattern array.

Extended Capabilities

Version History

Introduced in R2013b