categorical

Methods

Method Reference: categorical.eq

categorical: TF = eq (A, B)

Equality for categorical arrays.

TF = eq (A, B) is the equivalent of the syntax TF = A == B and returns a logical array of the same size as the largest input with its elements set to true where the corresponding elements of A and B are equal and set to false where they are not. A and B must be size compatible, which translates to they can be the same size, one can be scalar, or for every dimension, their dimension sizes must be equal or one of them must be 1.

If categorical arrays A and B are ordinal, they must have the same set and ordering of categories. If neither are ordinal, the category names of each pair of elements are compared. Hence, they do not need to have the same set of categories.

One of the input arguments can also be a character vector, a cellstr scalar or a string scalar as long as the other is a categorical array. In this case, a logical array of the same size as the categorical array is returned in which every element is tested for equality by comparing its category with that specified by the string argument.

Undefined elements always return false, since they are not comparable to any other categorical values including other undefined elements.

Source Code: categorical

Example: 1

eq (the == operator) compares a categorical array element by element, either to a single category name or to another categorical array. Equality works for every categorical — nominal or ordinal.

 C = categorical ({'M'; 'S'; 'L'; 'M'})
C =
  4x1 categorical array

    M    
    S    
    L    
    M

Which elements equal a given category?

 C == 'M'
ans =

  1
  0
  0
  1

Element-wise against a second array.

 C == categorical ({'M'; 'M'; 'L'; 'S'})
ans =

  1
  0
  1
  0