%% One-Hot Encode Subset of Classes
% If not all classes in the data are relevant, encode the data labels using only a subset of the classes.
% Create a row vector of data labels, where each column of the vector represents a single observation

pets = ["dog" "fish" "cat" "dog" "cat" "bird"];

% Define the list of classes to encode. These classes are a subset of those present in the observations.

animalClasses = ["bird"; "cat"; "dog"];

% One-hot encode the observations into the first dimension. Specify the classes to encode.

encPets = onehotencode(pets,1,"ClassNames",animalClasses)

% Observations of a class not present in the list of classes to encode are encoded to a vector of NaN values.
% Copyright 2020 The MathWorks, Inc.