convert categorical to numeric
3 个评论
采纳的回答
7 个评论
更多回答(5 个)
1 个评论
Calling categorical is a data conversion, so
c = categorical([12 12 13])
completely throws away the numeric values. In general, there is no way to get them back unless you have saved them, any more than you can get back the original values from int8([1.1 2.2 3.3]). Calling categorical is a data conversion.
That being said, you can certainly save the unique numeric values, and then index into those using the categorical array:
n = uniqueNumericValues(c)
You can also call double on a categorical, but what you will get back are the category numbers, not the original numeric values.
But here's the question: if you need to convert back to the original numbers, and you are not using meaningful category names when converting from those numbers, why use categorical to begin with? There may be things you haven't mentioned.
4 个评论
0 个评论
1 个评论
1 个评论
另请参阅
类别
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!