iscategory
Determine if inputs are names of categories
Description
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.
categories(A)
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
categories(A)
ans = 4×1 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.
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)tf = logical
1
Determine if any category names start with an X.
tf = iscategory(C,"X" + wildcardPattern)tf = logical
0
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
The
iscategory function fully supports tall arrays. For more information,
see Tall Arrays.
Usage notes and limitations:
The
catnamesinput argument does not support pattern expressions.
For more information, see Code Generation for Categorical Arrays (MATLAB Coder).
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
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.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- 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)