# Documentation

### This is machine translation

Translated by
Mouse over text to see original. Click the button below to return to the English verison of the page.

# removecats

Remove categories from categorical array

## Syntax

• ``B = removecats(A)``
example
• ``B = removecats(A,oldcats)``
example

## Description

example

````B = removecats(A)` removes unused categories from the categorical array, `A`. The output categorical array, `B`, has the same size and values as `A`. However, `B` possibly has fewer categories.```

example

````B = removecats(A,oldcats)` removes the categories specified by `oldcats`. The function `removecats` removes categories, but does not remove any elements of the array. Therefore, elements of `B`, whose values correspond to `oldcats`, are undefined.```

## Examples

collapse all

Create a categorical array representing political parties of four people.

```A = categorical({'republican' 'democrat' 'democrat' 'republican'},... {'democrat' 'republican' 'independent'}) ```
```A = republican democrat democrat republican ```

`A` is a 1-by-4 categorical array.

Summarize the categorical array, `A`.

```summary(A) ```
``` democrat republican independent 2 2 0 ```

`A` has three categories. `democrat` appears twice in the array, `republican` appears twice in the array, and `independent` is unused.

Remove the unused category, `independent`.

```B = removecats(A) ```
```B = republican democrat democrat republican ```

`B` has the same values as `A`.

Display the categories of `B`.

```categories(B) ```
```ans = 2×1 cell array 'democrat' 'republican' ```

`B` has fewer categories than `A`.

Create a categorical array, `A`, containing modes of transportation.

```A = categorical({'plane' 'car'; 'train' 'car'; 'plane' 'car'}) ```
```A = plane car train car plane car ```

`A` is a 3-by-2 categorical array.

Display the categories of `A`.

```categories(A) ```
```ans = 3×1 cell array 'car' 'plane' 'train' ```

`A` has three categories, `car`, `plane`, and `train`.

Remove the category, `train`.

```B = removecats(A,'train') ```
```B = plane car <undefined> car plane car ```

The element that was from the category `train` is now undefined.

Display the categories of `B`.

```categories(B) ```
```ans = 2×1 cell array 'car' 'plane' ```

`B` has one fewer category than `A`.

## Input Arguments

collapse all

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

Categories to remove, specified as a character vector or cell array of character vectors. The default is all the unused categories from `A`.

collapse all

### Tall Array Support

This function fully supports tall arrays. For more information, see Tall Arrays.

### Tips

• `~ismember(categories(A),unique(A))` returns logical `true` (`1`) for any unused category of `A`.