categorical of numbers to a numerical array
15 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
MathWorks Support Team
il 24 Lug 2018
Risposto: MathWorks Support Team
il 24 Lug 2018
I have a categorical with categories that are integers. How do I convert my categorical to a numerical array? When I call "double" it is giving an array with different numbers than my original numbering.
>> c = categorical(["5","3","2","1","8", "8", "2", "1"]);
>> d = double(c)
d =
4 3 2 1 5 5 2 1
Risposta accettata
MathWorks Support Team
il 24 Lug 2018
Categoricals do not use ordering in the same way as arrays or other data types.
categories(c)
ans =
5×1 cell array
{'1'}
{'2'}
{'3'}
{'5'}
{'8'}
Calling double on a categorical is just giving the ordering (alphabetically or numerically) of the values. So the lowest number (or earliest in the alphabet) is being defined as 1, then the second lowest is defined as 2 and so on.
Given the categorical above, 5 is the fourth highest so it becomes 4 and so on...
5 -> 4
3 -> 3
2 -> 2
1 -> 1
8 -> 5
To get these numbers into a double, you can first convert the categorical to a string and then to a double.
>> s= string(c);
>> d = double(s)
d =
5 3 2 1 8 8 2 1
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Categorical Arrays in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!