convertCategorical
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
Platform Compatibility
Windows macOS LinuxCategories
Tags
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
| Version | Published | Release Notes | |
|---|---|---|---|
| 1.0.0.0 | Description updated Description updated |
