MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
sizes and sizes2 are equivalent categorical arrays with the same ordering of
categories.

Convert a Categorical Array from Nonordinal to Ordinal

Create a nonordinal categorical array from the cell array of character vectors, A.

sizes3 = categorical(A)

sizes3 = 3x2 categorical array
medium large
small medium
large small

Determine if the categorical array is ordinal.

isordinal(sizes3)

ans = logical
0

sizes3 is a nonordinal categorical array with three categories,
{'large','medium','small'}. The categories of sizes3 are the sorted unique values
from A. You must use the input argument, valueset, to specify a different category
order.

Convert sizes3 to an ordinal categorical array, such that small < medium < large.

sizes3 = categorical(sizes3,{'small','medium','large'},'Ordinal',true);

sizes3 is now a 3-by-2 ordinal categorical array equivalent to sizes and sizes2.

Working with Ordinal Categorical Arrays


In order to combine or compare two categorical arrays, the sets of categories for both
input arrays must be identical, including their order. Furthermore, ordinal categorical
arrays are always protected. Therefore, when you assign values to an ordinal categorical
array, the values must belong to one of the existing categories. For more information see
“Work with Protected Categorical Arrays” on page 8-38.

8 Categorical Arrays

Free download pdf