convertCategorical

Version 1.0.0.0 (619 Bytes) by massie
A code to convert categorical vectors to double vectors or numerical arrays
36 Downloads
Updated 7 Jun 2018

View License

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 .

MATLAB Release Compatibility
Created with R2018a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Statistics and Machine Learning Toolbox in Help Center and MATLAB Answers
Version Published Release Notes
1.0.0.0

Description updated

Description updated