%% Decode Probability Vectors into Most Probable Classes
% Use onehotdecode to decode a set of probability vectors into the most probable class for each observation.
% Create a set of 10 random probability vectors. The vectors express the probability that an observation belongs to one of five classes.

numObs = 10;
numClasses = 5;

prob = rand(numObs,numClasses);

tot = sum(prob,2);
prob = prob./tot;

% Define the set of five classes.

classes = ["Red" "Yellow" "Green" "Blue" "Purple"];

% Decode the probabilities into the most probable classes. The probability vectors are encoded into the second dimension, so specify the dimension containing encoded probabilities as 2. Obtain the most probable classes as a vector of strings.

result = onehotdecode(prob,classes,2,"string")

% Copyright 2020 The MathWorks, Inc.