| Contents | Index |
Arrays for ordinal categorical data
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.
Use the ordinal constructor to create an ordinal array from a numeric, logical, or character array, or from a cell array of strings.
| ordinal | Construct ordinal categorical array |
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.
| ismember | Test for membership |
| mergelevels | Merge levels |
| sort | Sort elements of ordinal array |
| sortrows | Sort rows |
Methods in the following table are inherited from categorical.
| addlevels | Add levels to categorical array |
| cat | Concatenate categorical arrays |
| cellstr | Convert categorical array to cell array of strings |
| char | Convert categorical array to character array |
| circshift | Shift categorical array circularly |
| ctranspose | Transpose categorical matrix |
| disp | Display categorical array |
| display | Display categorical array |
| double | Convert categorical array to double array |
| droplevels | Drop levels |
| end | Last index in indexing expression for categorical array |
| flipdim | Flip categorical array along specified dimension |
| fliplr | Flip categorical matrix in left/right direction |
| flipud | Flip categorical matrix in up/down direction |
| getlabels | Access categorical array labels |
| getlevels | Get categorical array levels |
| hist | Plot histogram of categorical data |
| horzcat | Horizontal concatenation for categorical arrays |
| int16 | Convert categorical array to signed 16-bit integer array |
| int32 | Convert categorical array to signed 32-bit integer array |
| int64 | Convert categorical array to signed 64-bit integer array |
| int8 | Convert categorical array to signed 8-bit integer array |
| intersect | Set intersection for categorical arrays |
| ipermute | Inverse permute dimensions of categorical array |
| isempty | True for empty categorical array |
| isequal | True if categorical arrays are equal |
| islevel | Test for levels |
| ismember | True for elements of categorical array in set |
| isscalar | True if categorical array is scalar |
| isundefined | Test for undefined elements |
| isvector | True if categorical array is vector |
| length | Length of categorical array |
| levelcounts | Element counts by level |
| ndims | Number of dimensions of categorical array |
| numel | Number of elements in categorical array |
| permute | Permute dimensions of categorical array |
| reorderlevels | Reorder levels |
| repmat | Replicate and tile categorical array |
| reshape | Resize categorical array |
| rot90 | Rotate categorical matrix 90 degrees |
| setdiff | Set difference for categorical arrays |
| setlabels | Label levels |
| setxor | Set exclusive-or for categorical arrays |
| shiftdim | Shift dimensions of categorical array |
| single | Convert categorical array to single array |
| size | Size of categorical array |
| squeeze | Squeeze singleton dimensions from categorical array |
| subsasgn | Subscripted assignment for categorical array |
| subsindex | Subscript index for categorical array |
| subsref | Subscripted reference for categorical array |
| summary | Summary statistics for categorical array |
| times | Product of categorical arrays |
| transpose | Transpose categorical matrix |
| uint16 | Convert categorical array to unsigned 16-bit integers |
| uint32 | Convert categorical array to unsigned 32-bit integers |
| uint64 | Convert categorical array to unsigned 64-bit integers |
| uint8 | Convert categorical array to unsigned 8-bit integers |
| union | Set union for categorical arrays |
| unique | Unique values in categorical array |
| vertcat | Vertical concatenation for categorical arrays |
Properties in the following table are inherited from categorical.
| labels | Text labels for levels |
| undeflabel | Text label for undefined levels |
Value. To learn how this affects your use of the class, see Comparing Handle and Value Classes in the MATLAB Object-Oriented Programming documentation.
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[1] Johnson, N. L., S. Kotz, and A. W. Kemp, Univariate Discrete Distributions, 2nd edition, Wiley, 1992, pp. 124-130.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |