Convert double to categorical array
27 views (last 30 days)
I have a problem with convert double to categorical.
the matlab showed:
Error using categorical
Unable to create default category names. Specify category names using the CATEGORYNAMES input argument.
This is my code:
YTrain = trainYweekday';
YTrain = categorical(YTrain);
YTrain = num2cell(YTrain,1);
trainYweekday' is 1x360 double.
How can I convert trainYweekday to categorical?
Thank you very much.
Adam Danz on 16 Jun 2022
Edited: Adam Danz on 16 Jun 2022
The function categorical can convert continuous data into categorical data. However, this function cannot categorize two numbers if the difference between them is less than 5e-5, unless their differences are 0.
To get around this, you must discretize the vector
vals = [pi, pi+5e-5];
See this MathWorks Support Team article for more details.
Also see this example from the categorical doc page that shows the use of discretize to prevent this problem.