Create a 1-by-5 categorical vector.

A =
plane car train car plane

`A`

has three categories, `car`

, `plane`

,
and `train`

.

Find the number of elements in each category of `A`

.

The first element in `B`

corresponds to the
first category of `A`

, which is `car`

.
The second element in `B`

corresponds to the second
category of `A`

, which is `plane`

.
The third element of `B`

corresponds to the third
category of `A`

, which is `train`

.

Since `A`

is a row vector, `countcats`

returns
a row vector.

Create a 3-by-2 categorical array, `A`

,
from a numeric array.

A =
red blue
green red
blue red

`A`

has three categories, `red`

, `green`

,
and `blue`

.

Find the category counts of each column in `A`

.

The first row of `B`

corresponds to the first
category of `A`

. The value, `red`

,
occurs once in the first column of `A`

and twice
in the second column.

The second row of `B`

corresponds to the second
category of `A`

. The value, `green`

,
occurs once in the first column of `A`

, and it does
not occur in the second column.

The third row of `B`

corresponds to the third
category of `A`

. The value, `blue`

,
occurs once in the first column of `A`

and once in
the second column.

Create a 3-by-2 categorical array, `A`

,
from a numeric array.

A =
red blue
green red
blue red

`A`

has three categories, `red`

, `green`

,
and `blue`

.

Find the category counts of `A`

along
the second dimension.

The first column of `B`

corresponds to the
first category of `A`

. The value, `red`

,
occurs once in the first row of `A`

, once in the
second row, and once in the third row.

The second column of `B`

corresponds to the
second category of `A`

. The value, `green`

,
occurs in only one element. It occurs in the second row of `A`

.

The third column of `B`

corresponds to the
third category of `A`

. The value, `blue`

,
occurs once in the first row of `A`

and once in the
third row.

Create a 6-by-1 categorical array, `A`

,
from a numeric array.

A =
red
blue
green
red
blue
red

Remove the `blue`

category.

A =
red
<undefined>
green
red
<undefined>
red

`A`

has two categories, `red`

and `green`

.
Elements of `A`

that were from the `blue`

category
are now undefined.

Find the number of elements in each category of `A`

.

The first element in `B`

corresponds to the
first category of `A`

. The value, `red`

,
occurs three times in `A`

.

The second element in `B`

corresponds to the
second category of `A`

. The value, `green`

,
occurs once in `A`

.

`countcats`

does not return any information
on undefined elements.

Use the `summary`

function to view the
number of undefined elements in addition to the number of elements
in each category of `A`

.

red 3
green 1
<undefined> 2