Categories &

Functions List

Class Definition: categorical

Class: categorical

Array representing categorical data.

A categorical array represents an array of values that correspond to a finite set of discrete categories, which can be either ordinal (having a mathematical ordering) or nominal. It is an efficient way to define groups of rows in a table or to other types of variables.

Each categorical array stores the list of categories as a cell array of character vectors and a numeric array of uint16 type as indices to the categories. The categorical array may also store elements of undefined categorical values, which represent the absense of a given category and correspond to the NaN value for numeric arrays or in general to the missing value for other data types.

categorical arrays do not have any public properties, which can be indexed by using dot notation similarily to structures. However, there are several methods which can be used to modify their categories once they are constructed.

Source Code: categorical

Methods

categorical: C = categorical (A)
categorical: C = categorical (A, valueset)
categorical: C = categorical (A, valueset, catnames)
categorical: C = categorical (dots{, Name, Value)

Create a new array of categorical values.

A is the array of values to convert to categoricals.

valueset is the set of all values from which A is drawn. If omitted, it defaults to the unique values in A.

catnames is a list of category names corresponding to valueset. If omitted, it defaults to valueset, converted to strings.

Ordinal is a logical indicating whether the category values in C have a numeric ordering relationship. Defaults to false.

Protected indicates whether C should be protected, which prevents the addition of new categories to the array. Defaults to false.

C = categorical () returns an empty categorical array.

See also: categories, discretize, iscategorical

categorical: cstr = dispstrings (C)

Get display formatted strings for each element of a categorical array.

cstr = dispstrings (C) returns a cellstr array of character vectors, cstr, which has the same size as the input categorical C.

categorical: cstr = cellstr (C)

Convert categorical array to a cell array of character vectors.

cstr = cellstr (C) returns a cellstr array of character vectors, cstr, which has the same size as the input categorical C.

categorical: out = double (C)

Convert categorical array to a double array.

out = double (C) returns a double array indexing the categories in C. Categorical elements of undefined category are returned as NaN.

categorical: out = single (C)

Convert categorical array to a single array.

out = single (C) returns a single array indexing the categories in C. Categorical elements of undefined category are returned as NaN.

categorical: out = int64 (C)

Convert categorical array to a int64 array.

out = int64 (C) returns a int64 array indexing the categories in C. Categorical elements of undefined category are returned as 0.

categorical: out = int32 (C)

Convert categorical array to a int32 array.

out = int32 (C) returns a int32 array indexing the categories in C. Categorical elements of undefined category are returned as 0.

categorical: out = int16 (C)

Convert categorical array to a int16 array.

out = int16 (C) returns a int16 array indexing the categories in C. Categorical elements of undefined category are returned as 0. Note that the returned category indices saturate to intmax ('int16'), which is 32767.

categorical: out = int8 (C)

Convert categorical array to a int8 array.

out = int8 (C) returns a int8 array indexing the categories in C. Categorical elements of undefined category are returned as 0. Note that the returned category indices saturate to intmax ('int8'), which is 127.

categorical: out = uint64 (C)

Convert categorical array to a uint64 array.

out = uint64 (C) returns a uint64 array indexing the categories in C. Categorical elements of undefined category are returned as 0.

categorical: out = uint32 (C)

Convert categorical array to a uint32 array.

out = uint32 (C) returns a uint32 array indexing the categories in C. Categorical elements of undefined category are returned as 0.

categorical: out = uint16 (C)

Convert categorical array to a uint16 array.

out = uint16 (C) returns a uint16 array indexing the categories in C. Categorical elements of undefined category are returned as 0.

categorical: out = uint8 (C)

Convert categorical array to a int8 array.

out = uint8 (C) returns a uint8 array indexing the categories in C. Categorical elements of undefined category are returned as 0. Note that the returned category indices saturate to intmax ('uint8'), which is 255.

categorical: summary (C)

Display summary of categorical array.

summary (C) displays the number of elements in the categorical array C that are equal to each category of C. Any undefined elements in C are summed together and displayed as <undefined>.

categorical: cstr = categories (C)

List of categories in categorical array.

cstr = categories (C) returns a cell array of character vectors with the names of the categories in C.

categorical: sz = size (C)
categorical: dim_sz = size (C, dim)
categorical: dim_sz = size (C, d1, d2, …)
categorical: [rows, columns, …, dim_n_sz] = size (…)

Size of a categorical array.

sz = size (C) returns a row vector with the size (number of elements) of each dimension for the calendar duration array C.

dim_sz = size (C, dim) returns the size of the corresponding dimension specified in dim. If dim is a vector, then dim_sz is a vector of the same length and with each element corresponding to a specified dimension. Multiple dimensions may also be specified as separate arguments.

With a single output argument, size returns a row vector. When called with multiple output arguments, size returns the size of dimension N in the Nth argument.

categorical: out = ndims (calD)

Number of dimensions in a categorical array.

out = ndims (calD) returns the number of dimensions of the calendar duration array calD.

categorical: out = numel (calD)

Total number of elements in a categorical array.

For compatibility reasons with Octave’s OOP interface and subsasgn behavior, categorical’s numel is defined to always return 1.

categorical: TF = iscategory (C, catnames)

Test for categories in a categorical array.

TF = iscategory (C, catnames) returns a logical array TF of the same size as catnames containing true for each corresponding element of catnames that is a category in categorical array C and false otherwise.

categorical: TF = iscolumn (C)

Return true if categorical array is a column vector.

categorical: TF = isempty (C)

Return true if categorical array is empty.

categorical: TF = isequal (C1, C2, …)

Return true if categorical arrays are equal.

categorical: TF = isequaln (C1, C2, …)

Return true if categorical arrays are equal under the additional assumption that NaN == NaN.

categorical: TF = ismatrix (C)

Return true if categorical array is a 2-D array.

categorical: TF = ismember (A, B)
categorical: TF = ismember (A, B, 'rows')
categorical: [TF, index] = ismember (…)

Test for categorical elements in a set.

TF = ismember (A, B) returns a logical array TF of the same size as A containing true for each corresponding element of A that is in B and false otherwise. If A and B are both ordinal, they must both have the same ordered set of categories. If neither A nor B are ordinal, then this restriction is relaxed and comparison is performed using the category names. Comparison between an ordinal and an unordered categorical array is not allowed. A or B may also be a string array or a cell array of character vectors containing one or multiple category names to compare against.

TF = ismember (A, B, 'rows') only applies to categorical matrices with the same number of columns, in which case the logical vector TF contains true for each row of A that is also a row in B. TF has the size number of rows as A.

[TF, index] = ismember (A, B) also returns an index array of the same size as A containing the lowest index in B for each element of A that is a member of B and 0 otherwise. If the 'rows' optional argument is used, then the returning index is a column vector with the same rows as A and it contains the lowest index in B for each row of A that is a member of B and 0 otherwise.

categorical: TF = isordinal (C)

Test if categorical array is ordinal.

categorical: TF = isprotected (C)

Test if categorical array is protected.

categorical: TF = isrow (C)

Return true if categorical array is a row vector.

categorical: TF = isscalar (C)

Return true if categorical array is a scalar.

categorical: out = isundefined (C)

Test for undefined elements in categorical array.

TF = isundefined (C) returns a logical array TF of the same size as C containing true for each corresponding element of C that does not have a value from one of the categories in C and false otherwise.

categorical: TF = isvector (C)

Return true if categorical array is a vector.

categorical: B = addcats (A, newcats)
categorical: B = addcats (…, 'After', catname)
categorical: B = addcats (…, 'Before', catname)

Add categories to categorical array.

B = addcats (A, newcats) appends new categories specified in newcats to the categorical array A at the end of any existing categories. The output categorical array B does not contain elements that belong to the newly added categories.

B = addcats (…, 'After', catname) adds the categories after the existing category specified by catname.

B = addcats (…, 'Before', catname) adds the categories before the existing category specified by catname.

categorical: B = mergecats (A, oldcats)
categorical: B = mergecats (A, oldcats, newcat)

Merge categories in categorical array.

B = mergecats (A, oldcats) merges two or more categories specified by oldcats into a single category with the same name as oldcats(1). In case of ordinal categorical arrays, the categories listed in oldcats must be in consecutive order. All elements of A corresponding to the categories listed in oldcats are re-indexed to correspond to oldcats(1) in B.

B = mergecats (A, oldcats, newcat) merges the categories listed in oldcats into a single new category named as specififed by newcat.

categorical: B = removecats (A)
categorical: B = removecats (A, oldcats)

Remove categories from categorical array.

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

B = removecats (A, oldcats) removes the categories specified by oldcats. The elements of B that correspond to the removed categories are undefined.

categorical: B = renamecats (A, newnames)
categorical: B = renamecats (A, oldnames, newnames)

Rename categories in categorical array.

Renames some or all of the categories in obj, without changing any of its values.

categorical: B = reordercats (A)
categorical: B = reordercats (A, neworder)

Reorder categories in categorical array.

B = reordercats (A) reorders the categories of A in alphanumeric order.

B = reordercats (A, neworder) reorders the categories of A according to the order specified by neworder, which must be a cell array of character vectors or a string array with the same set of values as the existing categories in A.

categorical: B = setcats (A, newcats)

Set categories in categorical array.

B = setcats (A, newcats) sets categories in a categorical array according to the elements of the imput array and the categories specified by newcats.

  • Any element of A that corresponds to a category listed in newcats is copied to B with the same categorical value.
  • Any categories of A not listed in newcats are not copied to B and the corresponding elements of B are undefined.
  • New categories listed in newcats that are not present in A are added in B, but without any elements equal to these new categories.
categorical: C = times (A, B)

Combine categorical arrays.

C = times (A, B) is the equivalent of the syntax A .* B and returns a categorical array whose categories are the Cartesian product of the categories in A and B and each element is indexed to a new category which is the combination of the categories of the corresponding elements in A and B.

A and B must be of common size or scalars.

categorical.eq is not documented.
categorical.ge is not documented.
categorical.gt is not documented.
categorical.le is not documented.
categorical.lt is not documented.
categorical.ne is not documented.
categorical.sort is not documented.
categorical.sortrows is not documented.
categorical.sortrows is not documented.
categorical.intersect is not documented.
categorical.setdiff is not documented.
categorical.setxor is not documented.
categorical.union is not documented.