To convert categorical to double

119 次查看(过去 30 天)
Anjan
Anjan 2018-3-23
编辑: Walter Roberson 2024-8-18,20:24
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

回答(3 个)

cater re
cater re 2019-11-20
编辑:cater re 2019-11-20
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 2018-3-23
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 个评论
Anjan
Anjan 2018-3-23
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.

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2019-11-20
编辑:Walter Roberson 2024-8-18,20:24
catdata = categorical([2 7 3 50 5 6 60]);
catnames = categories(catdata);
converted = str2double(catnames(catdata)).'
converted = 1x7
2 7 3 50 5 6 60
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by