iscategory - Determine if inputs are names of categories - MATLAB (original) (raw)
Main Content
Determine if inputs are names of categories
Syntax
Description
tf = iscategory([A](#bt0y58o-1-A),[catnames](#bt0y58o-1-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
Create a categorical array.
A = categorical(["shirt" "pants"; "pants" "hat"; "shirt" "pants"])
A = 3×2 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 = 3×1 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 = 1×4 string "shirt" "pants" "socks" "shoes"
tf = iscategory(A,catnames)
tf = 1×4 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
, because it was not included in catnames
.
Create a categorical array.
data = ["plane" "car" "train" "car" "plane"]; categoriesOfData = ["boat" "car" "plane" "train"]; A = categorical(data,categoriesOfData)
A = 1×5 categorical plane car train car plane
ans = 4×1 cell {'boat' } {'car' } {'plane'} {'train'}
Determine if boat
is a category in A
.
tf = iscategory(A,"boat")
iscategory
returns 1
(true), even though no element of A
belongs to the category boat
.
Create a categorical array.
C = categorical(["Y" "Yes" "Yeah" "N" "No" "Nope"])
C = 1×6 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)
Determine if any category names start with an X
.
tf = iscategory(C,"X" + wildcardPattern)
Input Arguments
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
Theiscategory
function fully supports tall arrays. For more information, see Tall Arrays.
Version History
Introduced in R2013b