Main Content

iscategory

Test for categorical array categories

Description

example

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.

Examples

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.

categories(A)
ans = 3x1 cell
    {'hat'  }
    {'pants'}
    {'shirt'}

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
   1

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

Input Arguments

collapse all

Input array, specified as a categorical array.

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

Extended Capabilities

Introduced in R2013b