This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Test for categorical array categories


  • tf = iscategory(A,catnames)



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

Test for Categories

Create an ordinal categorical array, A.

A = categorical({'shirt' 'pants'; 'pants' 'hat'; 'shirt' 'pants'})
A = 

     shirt      pants 
     pants      hat   
     shirt      pants 

A is a 3-by-2 categorical array.

Test if the articles of clothing, shirt, pants, socks, and shoes, are categories of A.

catnames = {'shirt' 'pants' 'socks' 'shoes'};
tf = iscategory(A,catnames)
tf =

     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.

Test for Category with No Corresponding Data

Create a categorical array, A.

A = categorical({'plane' 'car' 'train' 'car' 'plane'},...
    {'boat' 'car' 'plane' 'train'})
A = 

     plane      car      train      car      plane 

A is a 1-by-5 categorical array.

Test to see if boat is a category in A.

tf = iscategory(A,'boat')
tf =


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

Input Arguments

collapse all

A — Categorical arrayvector | matrix | multidimensional array

Categorical array, specified as a vector, matrix, or multidimensional array.

catnames — Category namescharacter vector | cell array of character vectors | categorical array

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

Introduced in R2013b

Was this topic helpful?