# Documentation

### This is machine translation

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

# nominal

Create nominal array

After creating a `nominal` array, you can use related functions to add, drop, or merge categories, and more.

The `nominal` and `ordinal` array data types might be removed in a future release. To represent ordered and unordered discrete, nonnumeric data, use the MATLAB® `categorical` data type instead.

## Syntax

``B = nominal(X)``
``B = nominal(X,labels)``
``B = nominal(X,labels,levels)``
``B = nominal(X,labels,[],edges)``

## Description

````B = nominal(X)` creates a nominal array `B` from the array `X`. `nominal` creates the levels of `B` from the sorted unique values in `X`, and creates default labels for them.```

example

````B = nominal(X,labels)` labels the levels in `B` according to `labels`.```
````B = nominal(X,labels,levels)` creates a nominal array with possible levels defined by `levels`.```
````B = nominal(X,labels,[],edges)` creates a nominal array by binning a numeric array `X` with bin edges given by the numeric vector `edges`.```

## Examples

collapse all

Create nominal arrays from a cell array of character vectors and from integer data, and provide explicit labels.

Create a nominal array from a cell array of character vectors with values `'r'`, `'g'`, and `'b'`. Label these levels `'red'`, `'green'`, and `'blue'`, respectively. Note that the labels are specified according to the sorted (alphabetical) order of the elements in `X`.

```X = {'r' 'b' 'g';'g' 'r' 'b';'b' 'r' 'g'} B = nominal(X,{'blue','green','red'}) ```
```X = 3×3 cell array 'r' 'b' 'g' 'g' 'r' 'b' 'b' 'r' 'g' B = 3×3 nominal array red blue green green red blue blue red green ```

Create a nominal array from integer data with values 1 to 4, merging odd and even values into two nominal levels with labels `'odd'` and `'even'`. Achieve the merging by duplicating the labels.

```X = randi([1 4],5,2) B = nominal(X,{'odd','even','odd','even'}) ```
```X = 4 1 4 2 1 3 4 4 3 4 B = 5×2 nominal array even odd even even odd odd even even odd even ```

## Input Arguments

collapse all

Input array to convert to `nominal`, specified as a numeric, logical, character, or categorical array, or a cell array of character vectors. The levels of the resulting `nominal` array correspond to the sorted unique values in `X`.

Labels for the discrete levels, specified as a character array or cell array of character vectors. By default, `nominal` assigns the labels to the levels in `B` in order according to the sorted unique values in `X`.

You can include duplicate labels in `labels` in order to merge multiple values in `X` into a single level in `B`.

Data Types: `char` | `cell`

Possible nominal levels for the output `nominal` array, specified as a vector whose values can be compared to those in `X` using the equality operator. `nominal` assigns labels to each level from the corresponding elements of `labels`. If `X` contains any values not present in `levels`, the levels of the corresponding elements of `B` are undefined.

Bin edges to create a nominal array by binning a numeric array, specified as a numeric vector. The uppermost bin includes values equal to the right-most edge. `nominal` assigns labels to each level in the resulting nominal array from the corresponding elements of `labels`. When you specify `edges`, it must have one more element than `labels`.

## Output Arguments

collapse all

Nominal array, returned as a `nominal` array object.

By default, an element of `B` is undefined if the corresponding element of `X` is `NaN` (when `X` is numeric), an empty character vector (when `X` is a character), or undefined (when `X` is categorical). `nominal` treats such elements as "undefined" or "missing" and does not include entries for them among the possible levels. To create an explicit level for such elements instead of treating them as undefined, you must use the `levels` input argument, and include `NaN`, the empty character vector, or an undefined element.