主要内容

isprotected

Determine whether categories of categorical array are protected

Description

example

tf = iSprotection(A)returns logical1(真的) if the categories ofAare protected. Otherwise,isprotectedreturns logical0(false).

  • 真的— When you assign new values toB, the values must belong to one of the existing categories. Therefore, you only can combine arrays that have the same categories. To add new categories toB, you must use theaddcatsfunction.

  • false— When you assign new values toB, the categories update automatically. Therefore, you can combine (nonordinal) categorical arrays that have different categories. The categories can update to include the categories from both arrays.

Examples

collapse all

Create a categorical array containing the sizes of 10 objects. Use the namessmall,medium, 和largefor the values'S','M', 和'L'.

valueset = {'S','M','L'}; catnames = {'small','medium','大的'}; A = categorical({'M';'L';'S';'S';'M';'L';'M';'L';'M';'S'},...valueset,catnames,'Ordinal',真正的)
A =10x1分类medium large small small medium large medium large medium small

Ais a 10-by-1 categorical array.

Display the categories ofA.

类别(a)
ans =3x1 cell{'small' } {'medium'} {'large' }

Determine whether the categories ofAare protected.

tf = iSprotection(A)
tf =logical1

自从Ais an ordinal categorical array, the categories are protected. If you try to add a new value that does not belong to one of the existing categories, for exampleA(11)='Xlarge', then an error is returned.

First, useaddcatsto add a new category forxlarge.

A = addcats(A,'Xlarge','After','大的');

自从A受到保护,您现在可以添加一个值xlargesince it has an existing category.

A(11)='Xlarge'
A =11x1 categoricalmedium large small small medium large medium large medium small xlarge

Ais now a 11-by-1 categorical array with four categories, such thatsmall < medium < large < xlarge.

Input Arguments

collapse all

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

The categories of ordinal categorical arrays are always protected.

Extended Capabilities

H版istory

在R2013B中引入