MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
To add a new category for xlarge, use the addcats function. Since A is ordinal you must
specify the order for the new category.

A = addcats(A,'xlarge','After','large');

Now, assign a value for 'xlarge', since it has an existing category.

A(2) = 'xlarge'

A = 10x1 categorical array
medium
xlarge
small
small
medium
large
medium
large
medium
small

A is now a 10-by-1 categorical array with four categories, such that small < medium <
large < xlarge.

Combine Two Ordinal Categorical Arrays

Create another ordinal categorical array, B, containing the sizes of five items.

B = categorical([2;1;1;2;2],1:2,{'xsmall','small'},'Ordinal',true)

B = 5x1 categorical array
small
xsmall
xsmall
small
small

B is a 5-by-1 categorical array with two categories such that xsmall < small.

To combine two ordinal categorical arrays (which always have protected categories), they
must have the same categories and the categories must be in the same order.

Add the category 'xsmall' to A before the category 'small'.

8 Categorical Arrays

Free download pdf