iscategory
Determine if inputs are names of categories
Description
Examples
Determine If Names Are Categories
Create a categorical array.
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
, because it was not included in catnames
.
Test for Category with No Corresponding Data
Create a categorical array.
data = ["plane" "car" "train" "car" "plane"]; categoriesOfData = ["boat" "car" "plane" "train"]; A = categorical(data,categoriesOfData)
A = 1x5 categorical
plane car train car plane
categories(A)
ans = 4x1 cell
{'boat' }
{'car' }
{'plane'}
{'train'}
Determine if boat
is a category in A
.
tf = iscategory(A,"boat")
tf = logical
1
iscategory
returns 1
(true), even though no element of A
belongs to the category boat
.
Match Names of Categories by Using Pattern
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
1
Determine if any category names start with an X
.
tf = iscategory(C,"X" + wildcardPattern)
tf = logical
0
Input Arguments
A
— Input array
categorical
array
Input array, specified as a categorical
array.
catnames
— Category names
string array | character vector | cell array of character vectors | pattern
array
Category names, specified as a string array, character vector, cell array of character
vectors, or pattern
array.
Extended Capabilities
Tall Arrays
Calculate with arrays that have more rows than fit in memory.
The
iscategory
function fully supports tall arrays. For more information,
see Tall Arrays.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
The
catnames
input argument does not support pattern expressions.
For more information, see Code Generation for Categorical Arrays (MATLAB Coder).
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Distributed Arrays
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version History
Introduced in R2013b
See Also
categories
| categorical
| removecats
| mergecats
| renamecats
| reordercats
| ismember
| unique
| setcats
| addcats
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)