This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Change Category Labels

This example shows how to change the labels for category levels in categorical arrays using setlabels. You also have the option to specify labels when creating a categorical array.

Load sample data.

The variable Cylinders contains the number of cylinders in 100 sample cars.

load carsmall
ans =


The sample has 4-, 6-, and 8-cylinder cars.

Create an ordinal array.

Convert Cylinders to a nominal array with the default category labels (taken from the values in the data).

cyl  = ordinal(Cylinders);
ans =

  1x3 cell array

    {'4'}    {'6'}    {'8'}

ordinal created labels using the integer values in Cylinders, but you should provide labels for numeric data.

Change category labels.

Relabel the categories in cyl to Four, Six, and Eight.

cyl = setlabels(cyl ,{'Four','Six','Eight'});
ans =

  1x3 cell array

    {'Four'}    {'Six'}    {'Eight'}

Alternatively, you can specify category labels when you create a nominal or ordinal array using the second input argument, for example by specifying ordinal(Cylinders,{'Four','Six','Eight'}).

See Also

| | |

Related Examples

More About

Was this topic helpful?