Skip to Main Content Skip to Search
Product Documentation

ordinal class - Superclasses: categorical

Arrays for ordinal categorical data

Description

Ordinal arrays are used to store discrete values that have an ordering but are not numeric. An ordinal array provides efficient storage and convenient manipulation of such data, while also maintaining meaningful labels for the values. Ordinal arrays are often used as grouping variables.

Like a numerical array, an ordinal array can have any size or dimension. You can subscript, concatenate, reshape, sort, etc. ordinal arrays, much like ordinary numeric arrays. You can make comparisons between elements of two ordinal arrays, or between an ordinal array and a single string representing a ordinal value.

Construction

Use the ordinal constructor to create an ordinal array from a numeric, logical, or character array, or from a cell array of strings.

ordinalConstruct ordinal categorical array

Methods

Each ordinal array carries along a list of possible values that it can store, known as its levels. The list is created when you create an ordinal array, and you can access it using the getlevels method, or modify it using the addlevels, mergelevels, or droplevels methods. Assignment to the array will also add new levels automatically if the values assigned are not already levels of the array. The ordering on values stored in an ordinal array is defined by the order of the list of levels. You can change that order using the reorderlevels method.

The following table lists operations available for ordinal arrays.

ismemberTest for membership
mergelevelsMerge levels
sortSort elements of ordinal array
sortrowsSort rows

Inherited Methods

Methods in the following table are inherited from categorical.

addlevelsAdd levels to categorical array
catConcatenate categorical arrays
cellstrConvert categorical array to cell array of strings
charConvert categorical array to character array
circshiftShift categorical array circularly
ctransposeTranspose categorical matrix
dispDisplay categorical array
displayDisplay categorical array
doubleConvert categorical array to double array
droplevelsDrop levels
endLast index in indexing expression for categorical array
flipdimFlip categorical array along specified dimension
fliplrFlip categorical matrix in left/right direction
flipudFlip categorical matrix in up/down direction
getlabelsAccess categorical array labels
getlevelsGet categorical array levels
histPlot histogram of categorical data
horzcatHorizontal concatenation for categorical arrays
int16Convert categorical array to signed 16-bit integer array
int32Convert categorical array to signed 32-bit integer array
int64Convert categorical array to signed 64-bit integer array
int8Convert categorical array to signed 8-bit integer array
intersectSet intersection for categorical arrays
ipermuteInverse permute dimensions of categorical array
isemptyTrue for empty categorical array
isequalTrue if categorical arrays are equal
islevelTest for levels
ismemberTrue for elements of categorical array in set
isscalarTrue if categorical array is scalar
isundefinedTest for undefined elements
isvectorTrue if categorical array is vector
lengthLength of categorical array
levelcountsElement counts by level
ndimsNumber of dimensions of categorical array
numelNumber of elements in categorical array
permutePermute dimensions of categorical array
reorderlevelsReorder levels
repmatReplicate and tile categorical array
reshapeResize categorical array
rot90Rotate categorical matrix 90 degrees
setdiffSet difference for categorical arrays
setlabelsLabel levels
setxorSet exclusive-or for categorical arrays
shiftdimShift dimensions of categorical array
singleConvert categorical array to single array
sizeSize of categorical array
squeezeSqueeze singleton dimensions from categorical array
subsasgnSubscripted assignment for categorical array
subsindexSubscript index for categorical array
subsrefSubscripted reference for categorical array
summarySummary statistics for categorical array
timesProduct of categorical arrays
transposeTranspose categorical matrix
uint16Convert categorical array to unsigned 16-bit integers
uint32Convert categorical array to unsigned 32-bit integers
uint64Convert categorical array to unsigned 64-bit integers
uint8Convert categorical array to unsigned 8-bit integers
unionSet union for categorical arrays
uniqueUnique values in categorical array
vertcatVertical concatenation for categorical arrays

Properties

Inherited Properties

Properties in the following table are inherited from categorical.

labelsText labels for levels
undeflabelText label for undefined levels

Copy Semantics

Value. To learn how this affects your use of the class, see Comparing Handle and Value Classes in the MATLAB Object-Oriented Programming documentation.

Examples

Create an ordinal array from integer data:

quality = ordinal([1 2 3; 3 2 1; 2 1 3],{'low' 'medium' 'high'})

% Find elements meeting a criterion
quality >= 'medium'
ismember(quality,{'low' 'high'})

% Compare two ordinal arrays
quality2 = fliplr(quality)
quality == quality2

References

[1] Johnson, N. L., S. Kotz, and A. W. Kemp, Univariate Discrete Distributions, 2nd edition, Wiley, 1992, pp. 124-130.

See Also

histc | nominal

  


 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS