Effacer les filtres
Effacer les filtres

To convert categorical to double

129 vues (au cours des 30 derniers jours)
Anjan
Anjan le 23 Mar 2018
Commenté : Leonardo le 26 Juin 2024 à 3:14
Convert categorical '12' to double/numeric 12
%For example
Data=[2 36; 56 23]; %If i execute this data it will be in double format
To_categorical=categorical(Data); % then i am converting to categorical format
To_double= ???? % If i need to convert "TO_categorical" back to double
  2 commentaires
Ravindu Kodagoda Pathiranage
To_double = double(string(To_categorical));
Leonardo
Leonardo le 26 Juin 2024 à 3:14
Thanks!

Connectez-vous pour commenter.

Réponses (3)

cater re
cater re le 20 Nov 2019
Modifié(e) : cater re le 20 Nov 2019
If you have source. you can do it with below.
data = [2 7 3 50 5 6 60]
catdata = categorical(data)
catidx = double(catdata)
sdata = sort(data)
converted = sdata(catidx)
If there is no source, how to convert it?
catdata = categorical([2 7 3 50 5 6 60])
converted = str2num(char(catdata))'
If useful, thumb up!

KSSV
KSSV le 23 Mar 2018
Read about double
Data=[2 36; 56 23]; %If i execute this data it will be in double format
To_categorical=categorical(Data)
idx = double(To_categorical) ;
Data(idx)
  1 commentaire
Anjan
Anjan le 23 Mar 2018
This works only when there is still "Data=[2 36; 56 23];" in the workspace.
Please check the file with this attachment. I just want to convert that categorical table to double format.

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 20 Nov 2019
catdata = categorical([2 7 3 50 5 6 60]);
catnames = categories(catdata);
converted = str2double(catnames(catdata)).';

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by