Skip to content

reordercats

Reorder the categories of a categorical array.

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

Returns A with categories in a new order. With one argument, sorts alphabetically. With neworder (a cell array of category names in the desired order), uses that order. Especially relevant for ordinal arrays where order has semantic meaning.

reordercats(categorical({'b','a','c'}), {'c','b','a'})
  • categorical — Create a categorical array from data.
  • isordinal — Test whether the categorical array is ordinal.