Documentation Center

  • Trial Software
  • Product Updates

getlabels

Class: categorical

Access categorical array labels

The nominal and ordinal array data types might be removed in a future release. To represent ordered and unordered discrete, nonnumeric data, use the MATLAB® categorical data type instead.

Syntax

labels = getlabels(A)

Description

labels = getlabels(A) returns the labels of the levels in the categorical array A as a cell array of strings labels. For ordinal A, the labels are returned in the order of the levels.

Examples

Example 1

Display levels in a nominal and an ordinal array:

standings = nominal({'Leafs','Canadiens','Bruins'});
getlabels(standings)
ans = 
    'Bruins'  'Canadiens'  'Leafs'

standings = ordinal(1:3,{'Leafs','Canadiens','Bruins'});
getlabels(standings)
ans = 
    'Leafs'  'Canadiens'  'Bruins'

Example 2

Display age groups containing data in hospital.mat:

load hospital
edges = 0:10:100;
labels = strcat(num2str((0:10:90)','%d'),{'s'});
AgeGroup = ordinal(hospital.Age,labels,[],edges);
AgeGroup = droplevels(AgeGroup);
getlabels(AgeGroup)
ans = 
    '20s'    '30s'    '40s'    '50s'

See Also

|

Was this topic helpful?