Products & Services Industries Academia Support User Community Company

Learn more about Statistics Toolbox   

nominal - Class: nominal

Construct nominal categorical array

Syntax

B = nominal(A)
B = nominal(A,labels)
B = nominal(A,labels,levels)
B = nominal(A,labels,[],edges)

Description

B = nominal(A) creates a nominal array B from the array A. A can be numeric, logical, character, categorical, or a cell array of strings. nominal creates the levels of B from the sorted unique values in A, and creates default labels for them.

B = nominal(A,labels) labels the levels in B using the character array or cell array of strings labels. nominal assigns labels to levels in B in order according to the sorted unique values in A.

B = nominal(A,labels,levels) creates a nominal array with possible levels defined by levels. levels is a vector whose values can be compared to those in A using the equality operator. nominal assigns labels to each level from the corresponding elements of labels. If A contains any values not present in levels, the levels of the corresponding elements of B are undefined.

B = nominal(A,labels,[],edges) creates a nominal array by binning the numeric array A with bin edges given by the numeric vector edges. The uppermost bin includes values equal to the right-most edge. nominal assigns labels to each level in B from the corresponding elements of labels. edges must have one more element than labels.

By default, an element of B is undefined if the corresponding element of A is NaN (when A is numeric), an empty string (when A is character), or undefined (when A is categorical). nominal treats such elements as "undefined" or "missing" and does not include entries for them among the possible levels for B. To create an explicit level for such elements instead of treating them as undefined, you must use the levels input, and include NaN, the empty string, or an undefined element.

You may include duplicate labels in labels in order to merge multiple values in A into a single level in B.

Examples

Example 1

Create a nominal array from Fisher's iris data:

load fisheriris
species = nominal(species);
data = dataset(species,meas);
summary(data)
species: [150x1 nominal]
   setosa      versicolor      virginica 
       50              50             50 
meas: [150x4 double]
   min       4.3000         2         1    0.1000 
   1st Q     5.1000    2.8000    1.6000    0.3000 
   median    5.8000         3    4.3500    1.3000 
   3rd Q     6.4000    3.3000    5.1000    1.8000 
   max       7.9000    4.4000    6.9000    2.5000

Example 2

  1. Load patient data from the CSV file hospital.dat and store the information in a dataset array with observation names given by the first column in the data (patient identification):

    patients = dataset('file','hospital.dat',...
                       'delimiter',',',...
                       'ReadObsNames',true);
    
  2. Make the {0,1}-valued variable smoke nominal, and change the labels to 'No' and 'Yes':

    patients.smoke = nominal(patients.smoke,{'No','Yes'});
    
  3. Add new levels to smoke as placeholders for more detailed histories of smokers:

    patients.smoke = addlevels(patients.smoke,...
                     {'0-5 Years','5-10 Years','LongTerm'});
    
  4. Assuming the nonsmokers have never smoked, relabel the 'No' level:

    patients.smoke = setlabels(patients.smoke,'Never','No');
    
  5. Drop the undifferentiated 'Yes' level from smoke:

    patients.smoke = droplevels(patients.smoke,'Yes');
    
    Warning: OLDLEVELS contains categorical levels that 
    were present in A, caused some array elements to have 
    undefined levels.

    Note that smokers now have an undefined level.

  6. Set each smoker to one of the new levels, by observation name:

    patients.smoke('YPL-320') = '5-10 Years';

See Also

histc, ordinal

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS