isprotected
Tests whether the categories of a categorical array are protected.
Category: Language Fundamentals > Data Types
Syntax
tf = isprotected(C)
Returns true if the categorical array C is protected.
Description
In a protected categorical array, assigning a value that is not already a category is an error, instead of silently adding a new category. All ordinal arrays are protected. Create a protected array with the 'Protected' option of categorical.
Input arguments
C- A categorical array.
Output arguments
tf- Logical scalar.
Example
Protected and ordinal arrays
c = categorical({'lo','hi','lo'}, {'lo','hi'});
p = categorical({'lo','hi','lo'}, {'lo','hi'}, 'Protected', true);
o = categorical({'lo','hi'}, {'lo','hi'}, 'Ordinal', true);
isprotected(c)
isprotected(p)
isprotected(o)
Output
ans = logical
0
ans = logical
1
ans = logical
1