convertCategorical

A code to convert categorical vectors to double vectors or numerical arrays

You are now following this Submission

This code is to convert a categorical vector to a double or numeric vector using the grp2idx function. This is because the labels for LSTM networks and the Neural Network toolbox of MATLAB should be categorical, but you cannot compare two categorical variables or subtract them to find the RMSE, etc.
% An example demonstrating the idea behind this code:
% y = [0,1,3,4,6,0,1]
% ycat = categorical(y)
% [g,gN] = grp2idx(ycat)
% gN(g)
% ydouble = str2num(cell2mat(gN(g)))

Cite As

massie (2026). convertCategorical (https://www.mathworks.com/matlabcentral/fileexchange/67661-convertcategorical), MATLAB Central File Exchange. Retrieved .

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and MATLAB Answers

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

  • Windows
  • macOS
  • Linux
Version Published Release Notes Action
1.0.0.0

Description updated

Description updated